Reputation: 6423
I develop a desktop application that have to save running process with xml file. I have design and test already.
But I want to know how the catch the unexpected error that will make the application terminated to start save the running process.
Upvotes: 1
Views: 1900
Reputation: 1554
If your application is a web application, you can handle it in this manner:
//Method in global.asax.cs
void Application_Error(object sender, EventArgs e)
{
var lastError = Server.GetLastError();
//Log it using log4net
}
Additionally you can consider using elmah
Upvotes: 0
Reputation: 6878
You want to use the try / catch
construct. Basically you wrap the code you are concerned is going to error in a try { }
block and then immediately following is a catch { }
block of code that will run if an error was encountered. In this section you could do things like log the error, attempt to save to a different location, etc.
Refer to http://msdn.microsoft.com/en-us/library/0yd65esw%28v=vs.80%29.aspx for examples and information.
Upvotes: 0
Reputation: 101614
It's possible the following links may help:
You're (I believe) looking to bind to AppDomain.CurrentDomain.UnhandledException
Upvotes: 5