2021-03-29 19:34:45 +02:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
2022-10-11 16:31:57 +02:00
|
|
|
*
|
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
|
2021-05-23 20:43:50 +02:00
|
|
|
#define TRY_CATCH_OR_DO(block, action) \
|
2021-03-18 08:14:34 +01:00
|
|
|
try { block \
|
2021-03-16 21:36:13 +01:00
|
|
|
} catch (std::bad_alloc& e) { \
|
|
|
|
ESP_LOGE(TAG, "Out of memory"); \
|
2021-05-23 20:43:50 +02:00
|
|
|
action; \
|
|
|
|
} catch (::esp_modem::esp_err_exception& e) { \
|
2021-03-16 21:36:13 +01:00
|
|
|
esp_err_t err = e.get_err_t(); \
|
2022-07-18 17:08:15 +02:00
|
|
|
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()); \
|
2021-05-23 20:43:50 +02:00
|
|
|
action; \
|
2021-03-16 21:36:13 +01:00
|
|
|
}
|
2021-05-23 20:43:50 +02:00
|
|
|
|
|
|
|
#define TRY_CATCH_RET_NULL(block) TRY_CATCH_OR_DO(block, return nullptr)
|
2021-03-16 21:36:13 +01:00
|
|
|
#else
|
2021-05-23 20:43:50 +02:00
|
|
|
|
|
|
|
#define TRY_CATCH_OR_DO(block, action) \
|
|
|
|
block
|
|
|
|
|
2021-03-16 21:36:13 +01:00
|
|
|
#define TRY_CATCH_RET_NULL(block) \
|
|
|
|
block
|
2021-05-23 20:43:50 +02:00
|
|
|
|
2021-03-16 21:36:13 +01:00
|
|
|
#endif
|