Hi there,
I got some Code like:
After calling this method I want to test in the next method if there was an Exception.
And if so do something to react on this Exception.
Is there a way to do so?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jul 13, 2011, 4:52 AM
Prev MaxwelPosted Jul 12, 2011, 7:19 PM
Ok, more description is needed:
The "Main" application is a run-engine that is using the methods mentioned above.
Some of the methods are generated automatically (and therefore should not be changed). These methods are like Method 1. If there is an exception the run-engine logs this (this is one of the main purposes of it!) The Application does not terminate.
Now after a method of Type 1 a "CleanUp" is needed in a Method Type 2 depends on the fact if a exception occurs in the Type 1 Method.
But I see it I nor really Possible what I want to …
VulpesPosted Jul 10, 2011, 7:06 PM
The UnhandledException exception (and several other 'last chance' exceptions in the .NET Framework) are provided as a fall-back to allow you to log the exception and perhaps attempt some clean up before the application terminates.
Prev MaxwelPosted Jul 10, 2011, 6:45 PM
A handler for the AppDomain.UnhandledException catches an exception which is not otherwise caught, offering the opportunity to at least log it, before the application is terminated. However, it is not possible to prevent termination which occurs immediately after the handler has run.
What if the exception wouldn't terminate the application?The Methods are executed using a test engine, and the exception is logged in the results.
But this time I've to check in method2 if there was a exception in Method1.
The AppDomain.FirstChanceException provides a notification that an exception has occurred but doesn't actually handle it. The runtime searches for another eventhandler to do that. It therefore gives you the opportunity to examine any exceptions before they are handled or not.
This is sounds good.But looking throug the code examples ()
I think I would also have to change code in methode 1 ...
Also, if you're using .NET 4.0, you have to mark the eventhandlers for both these exceptions with the HandleProcessCorruptedStateExceptionsAttribute attribute if you want to catch an exception such as a stack overflow or access violation which corrupts the state of the process.
Hmm ...VulpesPosted Jul 10, 2011, 3:47 PM
Prev MaxwelPosted Jul 10, 2011, 1:48 PM
System.AppDomain.UnhandledException & System.AppDomain.FirstChanceException.
Not sure if this is the right, cause im very new to C#.
But maybe it is ok.
Prev MaxwelPosted Jul 5, 2011, 9:14 AM
Morcos AdelPosted Jul 5, 2011, 4:09 AM
this could approach what you're looking for
VulpesPosted Jul 5, 2011, 4:08 AM