C++ exceptions do not work inside threads

ThorstenS
Posts: 3
Joined: Sun Sep 17, 2017 11:52 am

C++ exceptions do not work inside threads

Postby ThorstenS » Fri Nov 10, 2017 2:27 pm

Hi,

I use ESP-IDF v3.01 (I guess, last commit is from Oct 19th). I enabled C++ exceptions and they work in the main program code. But when creating a thread using xTaskCreate() and with a try-catch block in the thread function, when a C++ exception is thrown, it does not reach the catch block. Instead it comes to a panic.

Code: Select all

0x40087b64: invoke_abort at D:/dev/esp-idf/components/esp32/panic.c:553

0x40087c63: abort at D:/dev/esp-idf/components/esp32/panic.c:553

0x4013550f: __cxxabiv1::__terminate(void (*)()) at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libstdc++-v3/libsupc++/eh_terminate.cc:112

0x40135556: std::terminate() at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libstdc++-v3/libsupc++/eh_terminate.cc:112

0x401344b3: __cxa_throw at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libstdc++-v3/libsupc++/eh_throw.cc:87

0x40107d21: ExceptionTestFunc() at d:\dev\msys32\opt\xtensa-esp32-elf\xtensa-esp32-elf\include\c++\5.2.0/functional:1871

0x40107d46: LightProtocolServerTask(void*) at d:\dev\msys32\opt\xtensa-esp32-elf\xtensa-esp32-elf\include\c++\5.2.0/functional:1871


LightProtocolServerTask() is my thread function. ExceptionTestFunc() is called by the thread function and throws an exception.

i_am_mrp
Posts: 11
Joined: Thu Sep 28, 2017 9:14 am

Re: C++ exceptions do not work inside threads

Postby i_am_mrp » Sun Nov 12, 2017 10:22 am

I think this is a FreeRTOS limitation vs. ESP-IDF (yes FreeRTOS is part of the ESP-IDF distro, see notes below)

FreeRTOS is not C++ aware and will just panic as you saw.

http://www.freertos.org/FreeRTOS_Suppor ... 03495.html

While the preceding link may be old and off ESP-IDF, I think it is still valid as an overall statement of affairs.

There are many extensions, wrappers, etc... that people have built for C++ enabled FreeRTOS but I haven't used any and I don't think ESP-IDF did either.

I am new to the ESP32 and have been using the ESP32 for a couple of months now with C++. I have only enabled exceptions when pulling in some libs that others have wrote (none of that code was using exceptions in FreeRTOS contexts though).

It seems more of us are using ESP-IDF with C++ and probably at some point either Espressif or our Community will tackle it fully.

Who is online

Users browsing this forum: No registered users and 1 guest