diff --git a/Robust.Server/Program.cs b/Robust.Server/Program.cs index 52c2067165b..af66f453310 100644 --- a/Robust.Server/Program.cs +++ b/Robust.Server/Program.cs @@ -126,13 +126,29 @@ internal static void SetupLogging(IDependencyCollection deps) AppDomain.CurrentDomain.UnhandledException += (sender, args) => { var message = ((Exception) args.ExceptionObject).ToString(); - uh.Log(args.IsTerminating ? LogLevel.Fatal : LogLevel.Error, message); + try + { + uh.Log(args.IsTerminating ? LogLevel.Fatal : LogLevel.Error, message); + } + catch (ObjectDisposedException) + { + // Avoid eating the exception if it's during shutdown and the sawmill is already gone. + System.Console.WriteLine($"UnhandledException but sawmill is disposed! {message}"); + } }; var uo = mgr.GetSawmill("unobserved"); TaskScheduler.UnobservedTaskException += (sender, args) => { - uo.Error(args.Exception!.ToString()); + try + { + uo.Error(args.Exception!.ToString()); + } + catch (ObjectDisposedException) + { + // Avoid eating the exception if it's during shutdown and the sawmill is already gone. + System.Console.WriteLine($"UnobservedTaskException but sawmill is disposed! {args.Exception}"); + } #if EXCEPTION_TOLERANCE args.SetObserved(); // don't crash #endif