how to catch any error on my C# program and show any message instead of crushed
i can do try & catch - but i don't know when or where in other place it will crush
i need something that will catch any unknown error
thanks in advance
how to catch any error on my C# program and show any message instead of crushed
i can do try & catch - but i don't know when or where in other place it will crush
i need something that will catch any unknown error
thanks in advance
If your exception is happening in a console app, or in a background thread on a win forms app, you can use the AppDomain.UnhandledException
event to determine what exception fired.
In the case of a Windows Forms application, use the Application.ThreadException
event.
In both cases, your application will still terminate, but it gives you an opportunity to log the exception and return gracefully. You can not use this to hide the exception, and continue running like nothing ever happened.
For completeness, if this is an ASP.NET application, then you can handle the error in the Application_Error
method in the global.asax file which is handling the HttpApplication.Error
event.