.NET Core Global exception handler in console application

孤街醉人 提交于 2019-12-10 12:33:26

问题


I'm porting an console application to .NET Core, and I'm trying to replace this line:

AppDomain.CurrentDomain.UnhandledException += UnhandledException;

After reading this, it seems there is no built-in way to do this.

So my question: is the only way to replace this line surrounding my entire code with a try/catch?

By reading this, it seems like there is another way, namely by keep on using System.AppDomain, but I can't seem to find this class/method. My only guess was this library, but it clearly states that it should not be used if possible, so I would like not to.


回答1:


You're right, the AppDomain.UnhandledException or it's analog will be available only in .Net Core 2.0, so for now you should either wait or add additional try/catch blocks. However, if you're using the tasks, you can use TaskScheduler.UnobservedTaskException, which is available from first version of .Net Core.



来源:https://stackoverflow.com/questions/43639601/net-core-global-exception-handler-in-console-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!