0

I think I know the function (call it function2) where the stackoverflow is occuring. However, I have added a try-catch statement around the whole function-body, put a break in the catch section but when the stackoverflow occurs it does not pause in the catch statement. However, if I go to the previous function (call it function1) which calls function2(), stepping over the function2() call does throw the exception.

I went to Debug -> Exceptions and most things are ticked.

I am using VS2012.

Are there any other ways I can check? This is what I essentially did:

void function1(){
    //Code does reach line below.
    function2();
    //Code never reaches here
}

void function2(){
    try{
        //All the logic for function2();
    }
    catch(exception& e){
        //I put a break point here but it never catches the break point
    }
}

EDIT: There is something in function2() which is causing this. The function does a lot of char processing and I have tried moving everything to pointers- but I still get the exception.

What is the best process to debug this problem in VS2012 if I cannot use exception-handling?

EDIT2: How can I see the stack size/growing in Visual Studio?

5
  • A stack overflow cannot be caught with a C++ catch statement. It requires structured exception handling with the non-standard __try/__except keywords. It is very unclear why you cannot diagnose this with the debugger. Commented Sep 21, 2013 at 15:54
  • Open the Call Stack window. That will show you. Commented Sep 21, 2013 at 16:22
  • @RaymondChen that only shows me which function? I want to see the stack size growing as I walk through the code... Commented Sep 21, 2013 at 16:54
  • Once you see which function is causing the problem, you can set a breakpoint on it. Commented Sep 21, 2013 at 17:23
  • It appears you reposted your question: Visual Studio- way to see the stack size growing whilst stepping through? Commented Sep 21, 2013 at 18:58

2 Answers 2

1

Stackoverflow is generated while you're entering the function2() body - so nothing from function2 will ever going to be executed, including the try-catch block.

Stackoveflow is not a exception like others and you can't catch it like others - it usually means that your memory model just got corrupted, and then you need to terminate your program - not much to do in this case.

See this reference for more info about catching them: Catching "Stack Overflow" exceptions in recursive C++ functions

Sign up to request clarification or add additional context in comments.

Comments

0

You can use the throw e inside your function 2 catch block, then you exception will be send to function1() and you can catch it on function 1 ..

3 Comments

Is there a setting I need to enable to ensure it does throw the exception? I went to debug and then C++ Exceptions and I ticked "std::exception" but it still doesn't appear to throw (I did throew e from within function2()).
you can simply use throw "Stack overflow exception occurred"; or you can use throw;
you saying insert "throw ""Cannot purturb at this time."" in to my C++ code?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.