I've been struggling to get exceptions to work properly on a Cortex-M4 project with the Arm's GCC distribution. The throw seems to work successfully but not the catch.
class MyExc : public std::exception { virtual const char* what() const noexcept { return "My exception!"; } } my_exc; int main(int argc, char* argv[]) { // Send a greeting to the trace device (skipped on Release). trace_puts("Hello ARM World!"); // At this stage the system clock should have already been configured // at high speed. trace_printf("System clock: %u Hz\n", SystemCoreClock); try { throw my_exc; } catch (...) { trace_printf("Caught exception\n"); } while(1); }
I've checked:
I've put together a minimal reproduction project at https://github.com/willson556/cortex-m-exception-test that builds with Eclipse Embedded CDT. I've been running that project in QEMU but the full project has the same problem on real hardware (an Infineon XMC4700).
If someone could point me to what I'm doing wrong in that project that would be really helpful. Thanks!
Reposted in the correct forum: community.arm.com/.../catching-c-exceptions-with-gcc-arm-none-eabi.