I think you're right, you donโt know what will go wrong.
However, you may also consider adding a handler to a ThreadException .
The above code will work, but there will be scenarios in which multithreading can be a problem with such code, since not all the code inside your Windows form program will be launched in the main thread of the Application.Run loop.
Here is a sample code from a related article:
[STAThread] static void Main() { System.Windows.Forms.Application.ThreadException += new ThreadExceptionEventHandler(ReportError); System.Windows.Forms.Application.Run(new MainForm()); } private static void ReportError(object sender, ThreadExceptionEventArgs e) { using (ReportErrorDialog errorDlg = new ReportErrorDialog(e.Exception)) { errorDlg.ShowDialog(); } }
Additional documentation on MSDN .
At a minor point, using the ThreadException event also allows you to continue the loop of your main message if the exception is not fatal (for example, fault tolerance scenarios), while the try / catch approach may need to restart the main message loop, which can cause side effects.
chakrit
source share