Our server costs ~$56 per month to run. Please consider donating or becoming a Patron to help keep the site running. Help us gain new members by following us on Twitter and liking our page on Facebook!
Current time: April 28, 2024, 8:20 pm

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom error message for stack overflow in C++
#1
Custom error message for stack overflow in C++
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.
Reply
#2
RE: Custom error message for stack overflow in C++
It's the admin punishing us for our insolence.
"Never trust a fox. Looks like a dog, behaves like a cat."
~ Erin Hunter
Reply
#3
RE: Custom error message for stack overflow in C++
(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.
Reply
#4
RE: Custom error message for stack overflow in C++
(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
‘But it does me no injury for my neighbour to say there are twenty gods or no gods. It neither picks my pocket nor breaks my leg.’ - Thomas Jefferson
Reply
#5
RE: Custom error message for stack overflow in C++
(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.
Reply
#6
RE: Custom error message for stack overflow in C++
(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?
Reply
#7
RE: Custom error message for stack overflow in C++
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!

Reply
#8
RE: Custom error message for stack overflow in C++
Try hitting it with a hammer.
[Image: extraordinarywoo-sig.jpg]
Reply
#9
RE: Custom error message for stack overflow in C++
(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.
Reply
#10
RE: Custom error message for stack overflow in C++
(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.
  
“If you are the smartest person in the room, then you are in the wrong room.” — Confucius
                                      
Reply



Possibly Related Threads...
Thread Author Replies Views Last Post
  What is the most absurd error message a program you have made was outputting? FlatAssembler 38 3884 June 14, 2023 at 8:01 am
Last Post: FlatAssembler
  Error 502 bad gateway for Rational Responders Brian37 13 1326 April 23, 2022 at 4:17 pm
Last Post: BrianSoddingBoru4
  How Do I Send an SMS message From UK mobile to a US one ReptilianPeon 11 1793 July 9, 2018 at 5:17 pm
Last Post: bennyboy
  HELPPPPP Blue screen error just now!!! Edwardo Piet 114 9997 November 10, 2015 at 2:26 am
Last Post: Aractus
  Disk read error. Creed of Heresy 12 4046 July 27, 2012 at 9:19 am
Last Post: Tiberius
  Video Error: Grey circle with a white exclaimation mark inside. Reforged 5 3749 July 5, 2012 at 1:19 am
Last Post: Reforged



Users browsing this thread: 1 Guest(s)