private static void SetGlobalExceptionHandler()
{
// Set exception handler. Needs to be done before we create splash screen
// (don't understand why, but otherwise some exceptions don't get caught)
// Using Application.ThreadException rather than
// AppDomain.CurrentDomain.UnhandledException has the advantage that the program
// doesn't necessarily ends - we can ignore the exception and continue.
Application.ThreadException += HandleTopLevelError;
// we also want to catch the UnhandledExceptions for all the cases that
// ThreadException don't catch, e.g. in the startup.
AppDomain.CurrentDomain.UnhandledException += HandleUnhandledException;
}