Stacktrace capture for all threads when throwing an exception

I work with an ASP.NET site maintained by WCF, where the service accidentally throws exceptions, eventually getting to the site and creating YSOD there. I suspect this is due to the problem of streaming to the backend, and would like to track the problem.

Is there an easy way to catch an uncaught exception on the WCF side, as well as grab a stack of all running threads, as well as restore the original exception with additional information?

This trace of multiple threads seems to be something that might be related to the framework or that someone else might have thought of it before, but I can't find anything.

+4
source share
1 answer

To catch stack traces of other threads, you will have to be in the debugger and view their stacks (for example, using the parallel stack window) when an exception occurs, but this does not allow sending Traces back.

You can use your code (that is, drag it in strategic places) to record stack traces that can be accessed by another thread, but this has unpleasant problems with performance, maintenance and elegance. Not to mention that it will only approximate what other threads do, as they could move independently, as an exception was thrown.

The only way I can think (and this is a hunch) is to somehow interrupt other threads, intercept the interrupt, save the stack trace, and then reset the interrupt. But this is likely to be a deterministic mess. Cancel is not recommended.

You will probably be best off working with the call profiler, generously logging and narrowing down the scope to find the root cause.

+2
source

All Articles