[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

StackOverflowException

Peter Larsen [CPH]

5/9/2008 1:38:00 PM

Hi,

I have a problem where a console-application throw a StackOverflowException
witout allowing me to receive a stacktrace and write it to a file.
It seems like the app doesn't allow me to do anything after a
StackOverflowException.

Is there a way to get some informations after a StackOverflowException ??

BR
Peter


10 Answers

Peter Duniho

5/9/2008 5:21:00 PM

0

On Fri, 09 May 2008 06:38:26 -0700, Peter Larsen [CPH]
<PeterLarsen@community.nospam> wrote:

> I have a problem where a console-application throw a
> StackOverflowException
> witout allowing me to receive a stacktrace and write it to a file.
> It seems like the app doesn't allow me to do anything after a
> StackOverflowException.
>
> Is there a way to get some informations after a StackOverflowException ??

Normally, you should be able to use the debugger to examine the state of
the application. But other than that, no...there's no way to successfully
recover from a StackOverflowException, at least not in .NET 2.0 and
later. This is intentionally part of .NET's design.

If you don't have an easy way to debug the exception, then you may be able
to find the problem by inspecting the code. A StackOverflowException is
almost always because of unbounded recursion. So look in your code for a
method that calls itself, either directly or indirectly (i.e. it calls
some other method that eventually results in calling the original method
again, again either directly or indirectly).

One of the most common ways I've seen for this to happen accidentally in
..NET code is when someone writes a property that references itself rather
than the correct class field that stores the value for the property. But
it could be anything really.

Pete

v-lliu

5/12/2008 6:25:00 AM

0

Thanks Pete for your reply!

Hi Peter,

The StackOverflowException is thrown when the execution stack overflows
because it contains too many nested method calls, typically in case of a
very deep or unbounded recursion.

An MSDN document says:

In prior versions of the .NET Framework, your application could catch a
StackOverflowException object (for example, to recover from unbounded
recursion). However, that practice is currently discouraged because
significant additional code is required to reliably catch a stack overflow
exception and continue program execution.

Starting with the .NET Framework version 2.0, a StackOverflowException
object cannot be caught by a try-catch block and the corresponding process
is terminated by default. Consequently, users are advised to write their
code to detect and prevent a stack overflow. For example, if your
application depends on recursion, use a counter or a state condition to
terminate the recursive loop.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default....
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/de....
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


Peter Larsen [CPH]

5/13/2008 2:30:00 PM

0

Hi Linda and Peter,

Thanks for your comments.

I now know that it isn't possible to catch a StackOverflowException :-(

I agree that it must be a recursion problem.
The problem is that some of the code is "build" at runtime from some xml
files and no one seems to know whether its the code-builder or some entries
in the xml files, that fails. It would be nice to know where the exception
is thrown, right !

Anyway, thanks for your time.

/Peter



Peter Duniho

5/13/2008 6:35:00 PM

0

On Tue, 13 May 2008 07:29:50 -0700, Peter Larsen [CPH]
<PeterLarsen@community.nospam> wrote:

> [...]
> I agree that it must be a recursion problem.
> The problem is that some of the code is "build" at runtime from some xml
> files and no one seems to know whether its the code-builder or some
> entries
> in the xml files, that fails. It would be nice to know where the
> exception
> is thrown, right !

It would be nice, yes. But it's not strictly speaking necessary.

The best scenario is that you can run the process in a debugger and get it
to crash. Then in the debugger, you'll be able to see where the exception
happens.

But the "non-best" scenario isn't that bad. First of all, I can tell you
for sure it's not your XML files per se. That's input, and no correct
program should ever crash just because it was given bad input. Besides
that, while XML processing does lend itself to recursion, the XML files
themselves should not be able to be created in a way that would result in
unbounded recursion. After all, that would require an infinitely large
XML file, or at the very least an exceptionally large one (with perhaps
millions of levels of nesting).

Now, is it possible that the XML files themselves somehow describe an
algorithm that your code builder creates that is itself flawed? I suppose
so. Ideally, you would not be building code from an XML description that
could result in that, but I don't know anything about the problem your
program actually solves so I can't say whether this ideal is achievable.
But, even if we assume that your XML describes a flawed algorithm, it
should be possible to track that down. In particular, you should be able
to keep a log of the code that's generated based on the XML, and then if
and when a crash happens, inspect the most-recently executed code to find
out why it crashed.

I agree that it would be a lot easier if there were a way for you to
catch, or at least log, the exception. But, I've debugged much harder
problems with less information and available resources. Your problem
isn't intractable. It's just going to require a bit more legwork. :)

Between judicious tracing of your program's execution, logging of data
processed and generated, and back-to-basics code inspection, it should be
solvable. The fact that this is almost certainly related to an issue with
recursion is a major clue, and should be able to help you drastically
reduce your search space.

Pete

Peter Larsen [CPH]

5/14/2008 10:34:00 AM

0

Hi Pete,

I think it is the xml files that describe a flow that failes somehow - just
like you say.
It happens very rarely - trying to debug after it, has not been a success
yet :-(

Anyway - thanks for you help.

/Peter


v-lliu

5/16/2008 8:17:00 AM

0

Thanks Pete for your help and excellent analysis!

Hi Peter,

> It happens very rarely - trying to debug after it, has not been a success
yet :-(

Do you mean the problem only appears seldomly?

If possible, you may send a sample project that can demonstrate the
problem, as well as the XML files to me. I'm willing to help you debug it.

To get my actual email address, remove 'online' from my displayed email
address.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.


v-lliu

5/20/2008 6:15:00 AM

0

Hi Peter,

How about the problem now?

If you need our further assistance, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.


Peter Larsen [CPH]

5/20/2008 7:44:00 AM

0

Hi Linda,

No, its the same.
I have just told the "boys" what you and Pete told me - that there is no
easy way here !!

It is not scheduled to be fixed in the nearest future - so just close down
this post.

Thanks for your help.
/Peter


"Linda Liu[MSFT]" <v-lliu@online.microsoft.com> wrote in message
news:pOilvDkuIHA.1788@TK2MSFTNGHUB02.phx.gbl...
> Hi Peter,
>
> How about the problem now?
>
> If you need our further assistance, please feel free to let me know.
>
> Thank you for using our MSDN Managed Newsgroup Support Service!
>
>


Peter Larsen [CPH]

5/20/2008 7:59:00 AM

0

Sorry Linda, i missed this post from you.
Thank you so much for offering your help with this, but i don't think it
would be necessary since it's way down on the list at the moment.


BR
Peter


"Linda Liu[MSFT]" <v-lliu@online.microsoft.com> wrote in message
news:TxGsK1ytIHA.1788@TK2MSFTNGHUB02.phx.gbl...
> Thanks Pete for your help and excellent analysis!
>
> Hi Peter,
>
>> It happens very rarely - trying to debug after it, has not been a success
> yet :-(
>
> Do you mean the problem only appears seldomly?
>
> If possible, you may send a sample project that can demonstrate the
> problem, as well as the XML files to me. I'm willing to help you debug it.


v-lliu

5/20/2008 9:10:00 AM

0

Hi Peter,

Thank you for your prompt response!

Well, I will close this issue in the newsgroup now. If you need our further
assistance, please feel free to re-open it and we will continue to work
with you at that time.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.