.NET Core Global Exception Handler in Console Application
I am porting a console application to .NET Core
, and I am trying to replace this line:
AppDomain.CurrentDomain.UnhandledException += UnhandledException;
After reading this , there doesn't seem to be a built-in way to do this.
So my question is, the only way to replace this line covering all of my code is try/catch
?
Reading this , it looks like there is another way, namely to keep using it System.AppDomain
, but I can't seem to find this class / method. My only guess was this library , but it clearly states that it cannot be used if possible, so I would not want to.
source to share
You're right, AppDomain.UnhandledException
or its analog will only be available in .Net Core 2.0 , so now you have to either wait or add additional blocks try/catch
. However, if you are using tasks, you can use TaskScheduler.UnobservedTaskException
which is available from the first version .Net Core
.
source to share