CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2007
    Posts
    17

    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;

    }

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    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.

  3. #3
    Join Date
    Aug 2009
    Posts
    10

    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

  4. #4
    Join Date
    Nov 2007
    Posts
    613

    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();
    }

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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
  •  





Click Here to Expand Forum to Full Width

Featured