Skip to content

Commit cd14b60

Browse files
committed
chore: 启动过程中的错误处理
1 parent 643898a commit cd14b60

1 file changed

Lines changed: 25 additions & 18 deletions

File tree

MaiChartManager/Program.cs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Text.Json;
2-
using System.Windows.Forms;
32

43
namespace MaiChartManager;
54

@@ -11,26 +10,34 @@ static class Program
1110
[STAThread]
1211
static void Main()
1312
{
14-
SentrySdk.Init(o =>
15-
{
16-
// Tells which project in Sentry to send events to:
17-
o.Dsn = "https://be7a9ae3a9a88f4660737b25894b3c20@sentry.c5y.moe/3";
18-
// Set TracesSampleRate to 1.0 to capture 100% of transactions for tracing.
19-
// We recommend adjusting this value in production.
20-
o.TracesSampleRate = 0.5;
21-
}
22-
);
13+
try
14+
{
15+
SentrySdk.Init(o =>
16+
{
17+
// Tells which project in Sentry to send events to:
18+
o.Dsn = "https://be7a9ae3a9a88f4660737b25894b3c20@sentry.c5y.moe/3";
19+
// Set TracesSampleRate to 1.0 to capture 100% of transactions for tracing.
20+
// We recommend adjusting this value in production.
21+
o.TracesSampleRate = 0.5;
22+
}
23+
);
2324

24-
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
25-
ApplicationConfiguration.Initialize();
25+
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
26+
ApplicationConfiguration.Initialize();
2627

27-
Directory.CreateDirectory(StaticSettings.appData);
28-
Directory.CreateDirectory(StaticSettings.tempPath);
29-
if (File.Exists(Path.Combine(StaticSettings.appData, "config.json")))
30-
StaticSettings.Config = JsonSerializer.Deserialize<Config>(File.ReadAllText(Path.Combine(StaticSettings.appData, "config.json")));
28+
Directory.CreateDirectory(StaticSettings.appData);
29+
Directory.CreateDirectory(StaticSettings.tempPath);
30+
if (File.Exists(Path.Combine(StaticSettings.appData, "config.json")))
31+
StaticSettings.Config = JsonSerializer.Deserialize<Config>(File.ReadAllText(Path.Combine(StaticSettings.appData, "config.json")));
3132

32-
new Launcher().Show();
33+
new Launcher().Show();
3334

34-
Application.Run();
35+
Application.Run();
36+
}
37+
catch (Exception e)
38+
{
39+
SentrySdk.CaptureException(e);
40+
MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
41+
}
3542
}
3643
}

0 commit comments

Comments
 (0)