C++ exceptions can sometimes fail causing a std::terminate on every throw. This turns out to be a linker issue present in the following files:
nRF5_SDK_17.0.2/components/toolchain/gcc/gcc_nrf51_common.ld
nRF5_SDK_17.0.2/modules/nrfx/mdk/nrf_common.ld
nRF5_SDK_17.0.2/modules/nrfx/mdk/nrf51_common.ld
nRF5_SDK_17.0.2/modules/nrfx/mdk/nrf52_common.ld
The section that needs changing is:
__exidx_start = .; .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) . = ALIGN(4); } > FLASH __exidx_end = .;
To:
.ARM.exidx : { __exidx_start = .; *(.ARM.exidx* .gnu.linkonce.armexidx.*) . = ALIGN(4); __exidx_end = .; } > FLASH
There's a good write up on this issue here:
https://community.nxp.com/t5/MCUXpresso-IDE/MCUX-11-1-0-C-exceptions-not-being-caught-w-solution/m-p/1015296
The main issue is that __exidz_start can sometimes be placed outside of the ARM.exidx region causing the stack unwinding to always fail
This issue isn't present in the Zephyr implementation as that contains the fixed version