Breaking on stack overflow #2159
-
In the course of using xUnit I sometimes run into situations where there's a self-referencing bug in my code which causes a stack overflow. This is when using xUnit within VS 2019 (latest updates installed). The bug is obviously my fault...but finding it is complicated by the fact the overflow doesn't manifest itself as a stack overflow. Instead, what eventually happens is the test crashes with an Access Violation. No exception is ever caught before this happens, even when I configure VS to not attempt to handle any exceptions. Why is this happening? Is there a way to configure xUnit so it does catch/throw overflow exceptions? I've noticed it handles other kinds of exceptions (e.g., ones thrown by Autofac when the DI container can't resolve a component).
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Well first off, you can only ever catch a Secondly, wow, I've never seen .NET terminate with an access violation. That's your OS dropping the hammer on .NET for touching memory that it doesn't own. You have no chance to recover from this, but you might be able to use a profiler (in instrumentation mode) to figure out where your execution was during the lead-up to the access violation. |
Beta Was this translation helpful? Give feedback.
-
Interesting. I wonder why I occasionally see stack overflow exceptions when I'm debugging (i.e., and not when I've thrown them specifically). Thanx for the feedback. |
Beta Was this translation helpful? Give feedback.
Well first off, you can only ever catch a
StackOverflowException
if you're the one who threw it.Secondly, wow, I've never seen .NET terminate with an access violation. That's your OS dropping the hammer on .NET for touching memory that it doesn't own. You have no chance to recover from this, but you might be able to use a profiler (in instrumentation mode) to figure out where your execution was during the lead-up to the access violation.