I have code that seems to have always worked until I tried it in a
particular situation in a catch-block, although even this situation looks
out of the ordinary, since it works fine in another catch-block. The service
crashes with EXCEPTION_STACK_OVERFLOW and the stack always points to the
same non-recursive function (or rather it opens an .ASM file dealing the
guard page and then it is always the same function). I ran the case in the
catch-block that did not cause this exception in the debugger and then it
did - in exactly the same place - and it continues to run fine outside the
debugger. The difference between the two cases is that in the first one the
object goes out of scope (before it reaches the catch-block) and then, once
a particular condition is detected, is re-created when the code returns to
the scope (while (service-is-running) try { X x; ... } catch (Y) {
disconnected ? make another turn; }) whilst in the second it is not
destroyed but rather manipulated through functions that cause
re-initialisation. In the debugger, the file with the guard page is opened
as soon as the function that appears at the top of the stack is entered.

The code is not particularly interesting but it should be noted that quite a
few functions are called and some of these in turn have their own
try-and-catch blocks inside them. It may well be that the number of
variables created along the way will consume the stack, although for that to
happen, I suspect, the stack that an application has when running inside a
catch-block should be smaller than usual, and it is this that I would like
to confirm. If the stack is smaller, is there way to find out how big it is
and how close I am to the limit?

Thank you.

Paul

RE: EXCEPTION_STACK_OVERFLOW caused by code executing in catch-block by v-garych

v-garych
Fri Oct 27 00:40:27 CDT 2006

Hi Paul,

>I suspect, the stack that an application has when running inside a
>catch-block should be smaller than usual, and it is this that I would
>like to confirm.

The Windows system reserves 1 MB of address space and commits 2 pages of
storage for each thread by default, the stack size should not be changed
while the thread is running (include the case of running inside a
catch-block). By the way, the defaults stack size could be changed by
specifying the /STACK option to the linker while you build your application
inside VS IDE.


>is there way to find out how big it is and how close I am to the limit?

There is no directly Windows API to check the stack usage. If you want to
check, you may need to use the Windbg to debug your application, it has a
command to view the process environment info including the stack's usage.

Thanks!

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



Re: EXCEPTION_STACK_OVERFLOW caused by code executing in catch-block by Oleg

Oleg
Fri Oct 27 01:32:31 CDT 2006


Just a small addition:

> >is there way to find out how big it is and how close I am to the limit?
>
> There is no directly Windows API to check the stack usage. If you want to
> check, you may need to use the Windbg to debug your application, it has a
> command to view the process environment info including the stack's usage.
>

Gary probably meant !teb command. Also, there is a way to check how much
stack space is occupied by each function on the call stack:
http://www.debuginfo.com/articles/easywindbg.html#debugstackoverflow

Also it makes sense to look at Debug Output window and check if there
are some suspicious first chance exceptions reported (and optionally
configure the debugger to break on first chance exceptions of that kind
(using Exceptions dialog) to see why they are thrown and where).

--
Oleg
[VC++ MVP http://www.debuginfo.com/]






Re: EXCEPTION_STACK_OVERFLOW caused by code executing in catch-block by Paul

Paul
Fri Oct 27 07:54:09 CDT 2006

Thank you - I think I have reached a conclusion.

The problem appears to have been caused by generous array allocations:

void function_a()
{
//...
execute();
//...
char col_buffer[MAX_COLS][MAX_COL_LEN];
short ind_buffer[MAX_COLS];
//...
}

execute() above threw an exception, so the code never got to the arrays.
However, the space they occupied does not seem to have been reclaimed on
exit from function_a(). For all I see, this was the consequence of the
exception execute() threw, since ordinarily the space would have been
returned. function_a() was called more than once by the code in the catch
{}. Had arrays been objects, to my knowledge they would not have been
constructed, or if the code had reached them and they had been, then their
destructors would have been called on exit from the scope. The space the
arrays occupied would too be returned at some point later, I should think,
but evidently not necessarily on return from function_a().

Paul