Posts: 2020
Threads: 133
Joined: July 26, 2017
Reputation:
5
Custom error message for stack overflow in C++
August 10, 2021 at 11:29 am
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.
Posts: 33350
Threads: 1420
Joined: March 15, 2013
Reputation:
152
RE: Custom error message for stack overflow in C++
August 10, 2021 at 11:34 am
It's the admin punishing us for our insolence.
"Never trust a fox. Looks like a dog, behaves like a cat."
~ Erin Hunter
Posts: 2020
Threads: 133
Joined: July 26, 2017
Reputation:
5
RE: Custom error message for stack overflow in C++
August 10, 2021 at 12:44 pm
(August 10, 2021 at 11:34 am)Foxaire Wrote: It's the admin punishing us for our insolence.
I have no idea what you are talking about.
Posts: 46505
Threads: 543
Joined: July 24, 2013
Reputation:
109
RE: Custom error message for stack overflow in C++
August 10, 2021 at 12:48 pm
(August 10, 2021 at 12:44 pm)FlatAssembler Wrote: (August 10, 2021 at 11:34 am)Foxaire Wrote: It's the admin punishing us for our insolence.
I have no idea what you are talking about.
It’s a little case of butthurt. It’ll clear up.
Boru
‘I can’t be having with this.’ - Esmeralda Weatherwax
Posts: 1664
Threads: 5
Joined: September 26, 2018
Reputation:
12
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.
Posts: 2020
Threads: 133
Joined: July 26, 2017
Reputation:
5
RE: Custom error message for stack overflow in C++
August 10, 2021 at 3:21 pm
(August 10, 2021 at 3:01 pm)HappySkeptic Wrote: (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. How can you check for the recursion depth? And how do you check how much stack space is left? Are those things even possible in standard C++?
Do you have some idea why that error would occur on CLANG and Visual Studio C++ but not on GCC?
Posts: 3297
Threads: 179
Joined: April 29, 2012
Reputation:
24
RE: Custom error message for stack overflow in C++
August 10, 2021 at 3:26 pm
Out of cheese error?
The meek shall inherit the Earth, the rest of us will fly to the stars.
Never underestimate the power of very stupid people in large groups
Arguing with an engineer is like wrestling with a pig in mud ..... after a while you realise that the pig likes it!
Posts: 29880
Threads: 116
Joined: February 22, 2011
Reputation:
159
RE: Custom error message for stack overflow in C++
August 10, 2021 at 3:36 pm
Try hitting it with a hammer.
Posts: 2020
Threads: 133
Joined: July 26, 2017
Reputation:
5
RE: Custom error message for stack overflow in C++
August 10, 2021 at 3:41 pm
(This post was last modified: August 10, 2021 at 3:42 pm by FlatAssembler.)
(August 10, 2021 at 3:36 pm)Angrboda Wrote: Try hitting it with a hammer.
To hit what with a hammer? The problem occurs on whatever computer my program, if compiled using CLANG without optimization or Visual Studio C++, is run on.
(August 10, 2021 at 3:26 pm)zebo-the-fat Wrote: Out of cheese error?
I am not sure what you mean.
Posts: 16663
Threads: 128
Joined: July 10, 2013
Reputation:
65
RE: Custom error message for stack overflow in C++
August 10, 2021 at 3:42 pm
(August 10, 2021 at 3:36 pm)Angrboda Wrote: Try hitting it with a hammer.
I think this step comes after turning it off and back on.
|