better exception message

This commit is contained in:
HolographicHat
2022-09-25 13:31:30 +08:00
parent b88858d2dc
commit 37bfb93fa9
4 changed files with 33 additions and 8 deletions

9
res/App.Designer.cs generated
View File

@@ -113,6 +113,15 @@ namespace YaeAchievement.res {
} }
} }
/// <summary>
/// Looks up a localized string similar to Network error ({0}: {1}).
/// </summary>
internal static string ExceptionNetwork {
get {
return ResourceManager.GetString("ExceptionNetwork", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Export to: /// Looks up a localized string similar to Export to:
///[0] Cocogoat (https://cocogoat.work/achievement, Default) ///[0] Cocogoat (https://cocogoat.work/achievement, Default)

View File

@@ -134,4 +134,7 @@ Input a number (0-5): </value>
<data name="VcRuntimeInstalling" xml:space="preserve"> <data name="VcRuntimeInstalling" xml:space="preserve">
<value>Installing Visual C++ Redistributable...</value> <value>Installing Visual C++ Redistributable...</value>
</data> </data>
<data name="ExceptionNetwork" xml:space="preserve">
<value>Network error ({0}: {1})</value>
</data>
</root> </root>

View File

@@ -128,4 +128,7 @@
<data name="VcRuntimeInstalling" xml:space="preserve"> <data name="VcRuntimeInstalling" xml:space="preserve">
<value>正在安装 Visual C++ Redistributable...</value> <value>正在安装 Visual C++ Redistributable...</value>
</data> </data>
<data name="ExceptionNetwork" xml:space="preserve">
<value>网络错误,请检查网络后重试 ({0}: {1})</value>
</data>
</root> </root>

View File

@@ -3,6 +3,7 @@ using System.Diagnostics;
using System.IO.Pipes; using System.IO.Pipes;
using System.Net; using System.Net;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Net.Sockets;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.Win32; using Microsoft.Win32;
using YaeAchievement.AppCenterSDK; using YaeAchievement.AppCenterSDK;
@@ -149,14 +150,23 @@ public static class Utils {
public static void InstallExceptionHook() { public static void InstallExceptionHook() {
AppDomain.CurrentDomain.UnhandledException += (_, e) => { AppDomain.CurrentDomain.UnhandledException += (_, e) => {
var ex = e.ExceptionObject; var ex = e.ExceptionObject;
if (ex is ApplicationException exception) { switch (ex) {
Console.WriteLine(exception.Message); case ApplicationException ex1:
} else { Console.WriteLine(ex1.Message);
Console.WriteLine(ex.ToString()); break;
Console.WriteLine(App.UploadError); case SocketException ex2:
AppCenter.TrackCrash((Exception) e.ExceptionObject); Console.WriteLine(App.ExceptionNetwork, nameof(SocketException), ex2.Message);
AppCenter.Upload(); break;
Environment.Exit(-1); case HttpRequestException ex3:
Console.WriteLine(App.ExceptionNetwork, nameof(HttpRequestException), ex3.Message);
break;
default:
Console.WriteLine(ex.ToString());
Console.WriteLine(App.UploadError);
AppCenter.TrackCrash((Exception) e.ExceptionObject);
AppCenter.Upload();
Environment.Exit(-1);
break;
} }
}; };
} }