fix: add exception handler for unobserved task exceptions

This commit is contained in:
goat 2020-03-27 16:39:46 +09:00
parent 9b39db6940
commit a92aad4a54

View file

@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using Dalamud.Interface;
using EasyHook;
using Serilog;
@ -25,14 +26,14 @@ namespace Dalamud {
// Log any unhandled exception.
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
using (var dalamud = new Dalamud(info)) {
using var dalamud = new Dalamud(info);
Log.Information("Starting a session..");
// Run session
dalamud.Start();
dalamud.WaitForUnload();
}
} catch (Exception ex) {
Log.Fatal(ex, "Unhandled exception on main thread.");
} finally {
@ -67,5 +68,11 @@ namespace Dalamud {
break;
}
}
private void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
if (!e.Observed)
Log.Error(e.Exception, "Unobserved exception in Task.");
}
}
}