This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Catching C++ Exceptions with GCC Arm None EABI

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). Output from building and running are in the build_log.txt and run_log.txt files.

If someone could point me to what I'm doing wrong in that project that would be really helpful. Thanks!

Originally posted at https://community.arm.com/developer/tools-software/tools/f/arm-compilers-forum/47347/catching-c-exceptions-with-gcc-arm-none-eabi which I now see was the wrong place.