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?

dandan78
  • 13,328
  • 13
  • 64
  • 78
user997112
  • 29,025
  • 43
  • 182
  • 361
  • 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. – Hans Passant Sep 21 '13 at 15:54
  • Open the Call Stack window. That will show you. – Raymond Chen Sep 21 '13 at 16:22
  • @RaymondChen that only shows me which function? I want to see the stack size growing as I walk through the code... – user997112 Sep 21 '13 at 16:54
  • Once you see which function is causing the problem, you can set a breakpoint on it. – Raymond Chen Sep 21 '13 at 17:23
  • It appears you reposted your question: [Visual Studio- way to see the stack size growing whilst stepping through?](http://stackoverflow.com/questions/18935282/visual-studio-way-to-see-the-stack-size-growing-whilst-stepping-through) – Raymond Chen Sep 21 '13 at 18:58

2 Answers2

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

Community
  • 1
  • 1
Nemanja Boric
  • 21,627
  • 6
  • 67
  • 91
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 ..

Arun Kumar
  • 907
  • 13
  • 33
  • 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()). – user997112 Sep 21 '13 at 16:02
  • you can simply use throw "Stack overflow exception occurred"; or you can use throw; – Arun Kumar Sep 21 '13 at 16:06
  • you saying insert "throw ""Cannot purturb at this time."" in to my C++ code? – user997112 Sep 21 '13 at 16:07