I want to use c++'s exception with arm-none-eabi-g++9.2.1 on Cortex-A9 board. But I found that, exception could be caught but "terminate" will also be called.
To use C++ exception, I've learned that I should do something as follows:
call __libc_init_array() when my RTOS starts up;
add some thing into linkscript:
.init_array :
{
// some symble that __libc_init_array will use...
}
.ARM.exidx : {
__exidx_start = .;
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
__exidx_end = .;
}
After 1 and 2, I try to run C++ exception in a task of RTOS(not c++'s thread):
// .cpp
// this is my custom exception
class MyE : public std::exception
{
...
}
// .cpp
// use custom exception
void myfunc(int value) {
try {
throw MyE();
} catch(MyE &e) {
printf("catch an exception\n"); // I've already implemented some stub funtions such as _write_r
}
printf("hello world outsize\n");
}
// .c
// test program
void app() {
myfunc();
}
And the result is as fllows:
catch an exception
hello world outsize
terminate called without an active exception
I want to know why terminate will be called, it seems the exception is caught successfully, but terminate was still called.
What shoud I do?
void app();keep spinning inside the loop, or maybe it exits and hits terminate at the end (for whatever reason)?