Casualties halting VS although being caught

Apr 19, 2012 at 4:42 PM

Hi Thomas,

Hope all is well.

I am dealing with a project and am using Casualties to get back the exception from my worker. I am running the project in VS but when an exception is thrown from a method on a component that I invoke, VS throws an unhandled exception but I have to Step Out of the project for the exception to get propagated up to where the message was posted from and my exception handler. I have based my code on  your example, ErrorHandlingWithCasualty but in your code, when the error is thrown, it does not throw an unhandled exception but is handled by the error port with no need to step out.

I was trying to figure out why this happens. Could it be that the error is being thrown by a call to a method in another class (and not directly from a line in the worker itself like your example) but then do you need to rethrow the error from the worker? I would have thought the exception would have bubbled up and you would not needed to explicitly rethrow the exception from the other assembly?

Any ideas gratefully received

Kind regards


Apr 20, 2012 at 1:10 PM

Hi Mike,

Unfortunately this is a problem that comes with this special way of handling exceptions. When you throw an exception, the ccr code that manages the running thread catches this exception and packs it into a causality message. By default Visual Studio is configured to automatically break any time when an exception is thrown in user code but not handled in user code - which is the case here since you intentionally let the exception through so it can be caught by the ccr. The only thing you can do to prevent Visual Studio from breaking is to switch it off under Debug->Exceptions by unchecking "User-handled" for CLR Exceptions. Or, if you know exactly which exception is thrown, you can also only switch off a single one. This is of course not the optimal solution because the Debugger won't break any more when these Exceptions occur anywhere, but unfortunately the only one I know. In the example solution also this way is used to prevent breaking.

Hope this helps!

Kind regards

Apr 23, 2012 at 10:24 AM

Thanks Thomas,

That makes sense now!

Many thanks