private static void Process(System.Exception exception) { lock (SyncRoot) { System.Environment.ExitCode = unchecked ((int)0x8000ffff); //E_UNEXPECTED(0x8000ffff) if (exception != null) { System.Diagnostics.Trace.TraceError(exception.ToString() + " {Medo.Application.UnhandledCatch}"); System.Windows.Forms.Application.ThreadException -= Application_ThreadException; System.AppDomain.CurrentDomain.UnhandledException -= AppDomain_UnhandledException; ThreadException?.Invoke(null, new ThreadExceptionEventArgs(exception)); } System.Diagnostics.Trace.TraceError("Exit(E_UNEXPECTED): Unhandled exception has occurred. {Medo.Application.UnhandledCatch}"); if (UnhandledCatch.UseFailFast) { System.Environment.FailFast(exception.Message); } else { System.Environment.Exit(unchecked ((int)0x8000ffff)); //E_UNEXPECTED(0x8000ffff) } } }
public static void Run(Form mainForm) { // TODO: Is an Application.Run replacement required? try { // err... } catch (Exception e) { // ... what is the sender anyway? ThreadException?.Invoke(mainForm, new ThreadExceptionEventArgs(e)); } }
/// <summary> /// called when a thread throws an exception /// </summary> /// <param name="ex">Exception thrown</param> protected void OnThreadException(Exception ex) { try { if (ex is ThreadAbortException && !ShouldReportThreadAbort) { return; } ThreadException?.Invoke(this, ex); } catch { } }
private bool RaiseExceptionEvent(Exception exception) { var args = new OperationUnhandledExceptionEventArgs(exception); ThreadException?.Invoke(this, args); if (!args.Handled) { args = new OperationUnhandledExceptionEventArgs(exception); if (!args.Handled) { return(false); } } return(true); }
/// <summary> /// called when a thread throws an exception /// </summary> /// <param name="ex">Exception thrown</param> public void OnThreadException(Exception ex) { try { if (ex is ThreadAbortException && !ShouldReportThreadAbort) { return; } if (ThreadException != null) { ThreadException.Invoke(this, ex); } } catch (Exception) { } }
protected virtual void OnThreadException(object exceptionObject) { ThreadException?.Invoke(this, new UnhandledExceptionEventArgs(exceptionObject, false)); }
protected virtual void AddException(Exception ex) { WithLock(() => _exceptions.Add(ex)); ThreadException?.Invoke(this, new ThreadExceptionEventArgs(ex)); }