3

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:

  1. call __libc_init_array() when my RTOS starts up;

  2. 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?

2
  • 1
    Check the assembly listing and see if stack unwinding is being handled properly. Commented Oct 31, 2024 at 14:32
  • 1
    Where is your toolchain from? A very popular one used to be compiled without exceptions. Also, is this even exception-related? I mean: does the void app(); keep spinning inside the loop, or maybe it exits and hits terminate at the end (for whatever reason)? Commented Oct 31, 2024 at 15:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.