Is it possible to handle all the errors in one place rather than writing try{} catch{} for all the blocks.
catch (Exception ex)
{
logger.Error(ex.Message);
ShowErrorMessage(ex.Message);
}
Is it possible to handle all the errors in one place rather than writing try{} catch{} for all the blocks.
catch (Exception ex)
{
logger.Error(ex.Message);
ShowErrorMessage(ex.Message);
}
You should generally handle exceptions as soon as possible unless you don't know how to handle them. For uncaught exceptions you can handle the AppDomain.UnhandledException and Application.ThreadException events. The UnhandledException
event will fire if an exception is thrown somewhere in your code but you haven't handled it. From MSDN:
[UnhandledException] provides notification of uncaught exceptions. It allows the application to log information about the exception before the system default handler reports the exception to the user and terminates the application. If sufficient information about the state of the application is available, other actions may be undertaken — such as saving program data for later recovery. Caution is advised, because program data can become corrupted when exceptions are not handled.
Yes. You need to register a uncaught exception. This can be done in Project settings "View Application Events" It's called MyApplication_UnhandledException