ThrowTheSwitch / CException

Lightweight exception implementation for C
http://throwtheswitch.org
MIT License
326 stars 66 forks source link

test_CanHaveNestedTryBlocksInASingleFunction_ThrowOutside() failed! #16

Closed tercelcn closed 3 years ago

tercelcn commented 4 years ago

Test test_CanHaveNestedTryBlocksInASingleFunction_ThrowOutside(), ' TEST_ASSERT_EQUAL(2, i) ' failed, i's value should be still zero.

mvandervoord commented 4 years ago

I'm assuming by this very brief bug that you are seeing a failure in the self-tests for your toolchain and target?

To help you debug this, It would be good to get some additional information. What compiler are you using? Are you running your tests natively or on a simulator or a target? etc.

Given which test you're seeing fail, it's possible your compiler has decided it can optimize i by not setting it inside the loop there... or that it hasn't written it back to the actual location of i in memory but still has it in a scratch register. If you change i to volatile, I suspect this test will get back to passing.

Otherwise maybe your concern is that the test itself is wrong? If this is the case, I'd encourage you to read the documentation. C doesn't have full stack unwinding the way C++ does, and CException's concept isn't to create a system with full stack unwinding. Instead, CException is meant to be a minimal lightweight error handling mechanism. It doesn't guarantee it will reverse the effects of any operations that happened on local variables within the Try blocks.

If your question was something else, I'd appreciate a bit more detail. Thanks so much! :)