Skip to content

Commit 8e46b74

Browse files
committed
More robust error handling for UI crashes.
1 parent b19016b commit 8e46b74

1 file changed

Lines changed: 36 additions & 18 deletions

File tree

EDDI/App.xaml.cs

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public partial class App : Application
2525
public static bool FromVA { get; set; }
2626
public static Action vaStartup;
2727

28-
[STAThread]
29-
public static void Main()
28+
[ STAThread ]
29+
public static void Main ()
3030
{
3131
if ( !FromVA && AlreadyRunning() )
3232
{
@@ -44,27 +44,49 @@ public static void Main()
4444
// Prepare to start the application
4545
Logging.IncrementLogs(); // Increment to a new log file.
4646
var configuration = ConfigService.Instance.eddiConfiguration;
47-
if (configuration != null && !configuration.DisableTelemetry)
47+
if ( configuration != null && !configuration.DisableTelemetry )
4848
{
4949
StartTelemetryService(); // do immediately to initialize error reporting
5050
}
51-
ApplyAnyOverrideCulture(configuration); // this must be done before any UI is generated
51+
52+
ApplyAnyOverrideCulture( configuration ); // this must be done before any UI is generated
5253

5354
// Start by fetching information from the update server, and handling appropriately
5455
EddiUpgrader.CheckUpgrade().GetAwaiter().GetResult();
5556

56-
if (FromVA)
57+
try
5758
{
58-
// Start with the MainWindow hidden
59-
EDDI.FromVA = FromVA;
60-
app.MainWindow = new MainWindow();
61-
vaStartup?.Invoke();
62-
app.Run();
59+
if ( FromVA )
60+
{
61+
// Start with the MainWindow hidden
62+
EDDI.FromVA = FromVA;
63+
app.MainWindow = new MainWindow();
64+
vaStartup?.Invoke();
65+
app.Run();
66+
}
67+
else
68+
{
69+
// Start by displaying the MainWindow
70+
app.Run( new MainWindow() );
71+
}
6372
}
64-
else
73+
catch ( Exception e )
6574
{
66-
// Start by displaying the MainWindow
67-
app.Run(new MainWindow());
75+
// Catch exceptions from the main UI thread
76+
CrashLogger( e );
77+
78+
// Attempt to restart the UI
79+
if ( FromVA )
80+
{
81+
// Start with the MainWindow hidden
82+
app.MainWindow = new MainWindow();
83+
app.Run();
84+
}
85+
else
86+
{
87+
// Start by displaying the MainWindow
88+
app.Run( new MainWindow() );
89+
}
6890
}
6991
}
7092

@@ -99,10 +121,6 @@ private static void StartTelemetryService()
99121
{
100122
CrashLogger(args.Exception);
101123
};
102-
Current.DispatcherUnhandledException += (sender, args) =>
103-
{
104-
CrashLogger(args.Exception);
105-
};
106124
// Catch and send unhandled exceptions from non-UI threads
107125
AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
108126
{
@@ -125,7 +143,7 @@ private static void CrashLogger(Exception ex)
125143
// Suppress uncaught Rollbar internal HTTP exceptions
126144
if ( ex is AggregateException aex &&
127145
aex.InnerException is HttpRequestException hre &&
128-
hre.StackTrace.Contains("Rollbar") )
146+
( hre.StackTrace?.Contains("Rollbar") ?? false ) )
129147
{
130148
return;
131149
}

0 commit comments

Comments
 (0)