RE: Custom error message for stack overflow in C++
August 10, 2021 at 3:01 pm
(This post was last modified: August 10, 2021 at 3:02 pm by HappySkeptic.)
(August 10, 2021 at 11:29 am)FlatAssembler Wrote: Hey, guys!
So, there is a bug in the compiler for my programming language, written in C++, that results in a Stack Overflow error: https://github.com/FlatAssembler/AECforW...y/issues/5
I am interested whether I can, until I find a way fix it (I have not even diagnosed it exactly yet), at least provide a custom error message when it happens, which is informative (that the error does not seem to occur if it is compiled with GCC or if optimizations are enabled in CLANG) and links to the issue on GitHub. You can easily provide custom error messages using C signals (parts of the C++ standard library) in case of Segmentation Fault or Division by Zero Error, however, to my surprise, there does not seem to be an easy way to give a custom error messages in case of Stack Overflow error.
A quick google search (on the site stackoverflow) suggests it is possible in Windows, but very difficult.
A stack overflow is usually a fatal error for a thread.
In your case, it is probably caused by an infinite recursive loop (or you have too small a stack set). You need to fix that by perhaps checking your recursion depth and erroring out before the overflow, or else just fixing your compiler.