diff --git a/Common/Internationalization/Message/LanguageCHS.cs b/Common/Internationalization/Message/LanguageCHS.cs index dbf032f9..6466c2a4 100644 --- a/Common/Internationalization/Message/LanguageCHS.cs +++ b/Common/Internationalization/Message/LanguageCHS.cs @@ -155,6 +155,8 @@ public class ServerInfoTextCHS public string UnloadedItems => "卸载了所有 {0}。"; public string SaveDatabase => "已保存数据库,用时 {0}s"; public string WaitForAllDone => "现在还不可以进入游戏,请等待所有项目加载完成后再试"; + + public string UnhandledException => "发生未经处理的异常:{0}"; } #endregion diff --git a/Common/Internationalization/Message/LanguageCHT.cs b/Common/Internationalization/Message/LanguageCHT.cs index 92e9be51..cb44eae7 100644 --- a/Common/Internationalization/Message/LanguageCHT.cs +++ b/Common/Internationalization/Message/LanguageCHT.cs @@ -153,6 +153,8 @@ public class ServerInfoTextCHT public string UnloadedItems => "卸載了所有 {0}。"; public string SaveDatabase => "已保存數據庫,用時 {0}s"; public string WaitForAllDone => "現在還不可以進入遊戲,請等待所有項目加載完成後再試"; + + public string UnhandledException => "未處理的異常:{0}"; } #endregion diff --git a/Common/Internationalization/Message/LanguageEN.cs b/Common/Internationalization/Message/LanguageEN.cs index eb87f74f..c5c2f5f8 100644 --- a/Common/Internationalization/Message/LanguageEN.cs +++ b/Common/Internationalization/Message/LanguageEN.cs @@ -158,6 +158,8 @@ public class ServerInfoTextEN public string SaveDatabase => "Database saved in {0}s"; public string WaitForAllDone => "You cannot enter the game yet. Please wait for all items to load before trying again"; + + public string UnhandledException => "An unhandled exception occurred: {0}"; } #endregion diff --git a/Program/Program/EntryPoint.cs b/Program/Program/EntryPoint.cs index 67249c91..475fd9fe 100644 --- a/Program/Program/EntryPoint.cs +++ b/Program/Program/EntryPoint.cs @@ -32,6 +32,14 @@ public class EntryPoint Logger.Info(I18NManager.Translate("Server.ServerInfo.Shutdown")); PerformCleanup(); }; + AppDomain.CurrentDomain.UnhandledException += (obj, arg) => + { + Logger.Error(I18NManager.Translate("Server.ServerInfo.UnhandledException", obj.GetType().Name), (Exception)arg.ExceptionObject); + Logger.Info(I18NManager.Translate("Server.ServerInfo.Shutdown")); + PerformCleanup(); + Environment.Exit(1); + }; + Console.CancelKeyPress += (_, eventArgs) => { Logger.Info(I18NManager.Translate("Server.ServerInfo.CancelKeyPressed"));