private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { var ex = e.ExceptionObject as Exception; ServerConsole.Write(EConsoleColor.Error, e.IsTerminating ? "Error: " : "Warning: "); ServerConsole.WriteLine(EConsoleColor.Error, Tools.CleanExcepionStacktrace(ex.Message)); if (ex.StackTrace != string.Empty) { ServerConsole.WriteLine(ex.StackTrace); } if (e.IsTerminating == false) { return; } mCrashed = true; var close = false; try { var args = new CrashedEventArgs(e.ExceptionObject as Exception); Events.InvokeCrashed(args); close = args.Close; } catch (Exception) { } if (!close) { SocketPool.Destroy(); ServerConsole.ErrorLine("This exception is fatal, press return to exit"); ServerConsole.Read(); } mClosing = true; }