Files
esp-protocols/components/esp_modem/private_include/exception_stub.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
808 B
C++
Raw Normal View History

2021-03-29 19:34:45 +02:00
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
2021-03-29 19:34:45 +02:00
* SPDX-License-Identifier: Apache-2.0
*/
2021-03-16 21:36:13 +01:00
2021-05-26 15:57:25 +02:00
#pragma once
2021-03-16 21:36:13 +01:00
#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
#define TRY_CATCH_OR_DO(block, action) \
try { block \
2021-03-16 21:36:13 +01:00
} catch (std::bad_alloc& e) { \
ESP_LOGE(TAG, "Out of memory"); \
action; \
} catch (::esp_modem::esp_err_exception& e) { \
2021-03-16 21:36:13 +01:00
esp_err_t err = e.get_err_t(); \
ESP_LOGE(TAG, "%s: Exception caught with ESP err_code=%d %s", __func__, err, esp_err_to_name(err)); \
2021-03-16 21:36:13 +01:00
ESP_LOGE(TAG, "%s", e.what()); \
action; \
2021-03-16 21:36:13 +01:00
}
#define TRY_CATCH_RET_NULL(block) TRY_CATCH_OR_DO(block, return nullptr)
2021-03-16 21:36:13 +01:00
#else
#define TRY_CATCH_OR_DO(block, action) \
block
2021-03-16 21:36:13 +01:00
#define TRY_CATCH_RET_NULL(block) \
block
2021-03-16 21:36:13 +01:00
#endif