A
assaf
hi all
i need to catch a Runtime Stack Overflow Exception.
how can i do this?
assaf
i need to catch a Runtime Stack Overflow Exception.
how can i do this?
assaf
Alvin Bruney said:during stack overflow, finally blocks won't fire because there is no space
left. catching that exception is usually a sign of poor design. a stack
overflow should be allowed to take down the whole parade.
How an application responds to a stack overflow is a policy
decision that a hosting application should be able to make.
Alvin Bruney said:hmmm, a few concerns come to mind (not thoroughly thought thru btw)
the stack overflow may or may not be coming from the plugin so catching
all stack overflows is not guaranteed to fix the broken case
I agree, with the caveat that critical cleanup code on non-faulted threadsin the case of a plugin running in its own separate appdomain, the
appdomain should isolate the hosting application from the catastrophic
failure. but you shouldn't attempt to catch the stack exception. the app
domain should be allowed to crash and the hosting application should simply
log the failure. no clean up is needed because the crashed appdomain should
be automatically unloaded.
in the case of the plugin running on a separate thread, it should be
allowed to kill the hosting application as well. the failure will be
restricted to the hosting app domain so it won't take down the webserver for
instance (on IIS 6 for instance, lesser versions will die).
So i'm not really clear what you mean by policy.
--
That answers the question, at least for this version of the runtime - it isassaf said:hi david
i am running on a 'worker' thread.
with try-catch
nevertheless, it crashes the app.
assaf said:there must be a way to prevent the application from crashing.
the stack-overflowing thread is just a background graphics analysis
operation.
my system should be able to recover from it.
here is its code that blows up the stack:
RectangleF[] rects = this._Region..GetRegionScans(this._Matrix);
as u can see, it is caused by a Region containing too many rectangles.
since a RectangleF is a struct, a value type,
the entire array is allocated on the stack.
Jon Skeet said:assaf said:there must be a way to prevent the application from crashing.
the stack-overflowing thread is just a background graphics analysis
operation.
my system should be able to recover from it.
here is its code that blows up the stack:
RectangleF[] rects = this._Region..GetRegionScans(this._Matrix);
as u can see, it is caused by a Region containing too many rectangles.
since a RectangleF is a struct, a value type,
the entire array is allocated on the stack.
No it's not. Arrays themselves are *always* reference types. The values
will be on the heap. It's more likely that GetRegionScans is recursing
too deeply.
assaf said:so what is the solution?
we are talking about a background analysis thread
that if it fails, the app could do without it.
the crash only happens when the system is overwhelmed with user input.
this is rare, but i would rather catch the exception then shut down
unexpectedly.
please help me.
assaf said:ok,
so what is the solution?
we are talking about a background analysis thread
that if it fails, the app could do without it.
the crash only happens when the system is overwhelmed with user input.
this is rare, but i would rather catch the exception then shut down
unexpectedly.
please help me.
private RectangleF[] GetRegionScans(Region re)
{
Matrix m = new Matrix();
m.Reset();
RectangleF[] rects = re.GetRegionScans(m); // this line throws the
StackOverflowException!!!
return rects;
}