|
-
September 3rd, 2009, 11:43 AM
#1
Stack Overflow happening but no exception thrown
Hi
I am learning to debug with Visual Studio and created a program to throw a stack overflow exception.
When I run it in the debugger it does throw but when I just run it from the command line no exception is thrown. Why?
void Example6_1();
void Example6()
{
Example6_1();
}
void Example6_1()
{
Example6();
}
int main()
{
Example6();
return 0;
}
-
September 3rd, 2009, 11:51 AM
#2
Re: Stack Overflow happening but no exception thrown
I don't think you can rely on anything in particular happening when you hit a stack overflow. If Visual Studio is nice enough to do something exception-like in some cases that's great, but I don't believe anything is guaranteed.
-
September 3rd, 2009, 12:38 PM
#3
Re: Stack Overflow happening but no exception thrown
its a recursive function, never ends, this will blow up the stack
nvm: i missed the part that you said you wanted to make it blow up :P
-
September 3rd, 2009, 01:38 PM
#4
Re: Stack Overflow happening but no exception thrown
As Lindley said, you cannot relay on a specific behaviour. In such cases anything may happen.
Actually, I'm quite sure your code will stop running almost instantly as soon as the stack is full, even though no message is displayed.
Try to place a TRACE1 function inside your code to display something variable in the output window. I'm sure it will freeze slowly. (The speed of the execution will be severely slowed down by the continuous scrolling of the output window.)
A much simpler code to trigger a stack overflow is:
Code:
void Func()
{
Func();
}
-
September 4th, 2009, 04:00 AM
#5
Re: Stack Overflow happening but no exception thrown
Depending on how your Windows is configured, it's entirely possible said exe is indeed causing a stack overflow but no window or error message is being displayed. Check the Application event log, you should be able to find it there.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|