4

I ask this question because soon I'll have interview heavily focused on error handling but also this is something I haven't figure out even though I have almost 7 months as a junior C# developer.

As the title says I want to know what is the right way to deal with exceptions form which there is no appropriate error handler. Some time ago I've heard a colleague of mine talking about generic exception handler (whatever that may mean) which is responsible to deal with suck case scenarios. However I did I little googling I haven't been able to find some information about such a thing.

So my question is - how to deal with those kind of exceptions and my subquestion is - is there really something called generic exception handler?

4

3 回答 3

5

真的有一种叫做通用异常处理程序的东西吗?

是的 - 这就是他们所说的记录异常并在退出程序之前存储尽可能多的信息的处理程序。像这样设置处理程序的一种方法是将处理程序添加到对象的UnhandledException事件中AppDomain

它既不是 .NET 意义上的“泛型”也不是“处理程序”,因为不涉及泛型类型,并且处理程序可以采取的操作相当有限。与可以阻止或重新抛出它处理的异常的真正处理程序不同,最后机会的“处理程序”可以看到抛出的内容,但不能导致执行继续。

于 2013-09-22T12:18:26.000 回答
1

处理计划外异常的方法是捕获它们,将它们记录到开发人员将检查它们是否存在错误的某个地方,然后以这种方式中止正在尝试的操作。这可能意味着您向用户显示错误消息、关闭应用程序或让 ASP.NET 之类的框架处理异常(它将通过显示通用错误页面来“处理”它)。

由于错误,总是会发生计划外的异常。您需要一个策略来处理它(如上所述)。

“通用”异常处理程序将是catch (Exception ex). 换句话说,包罗万象。这不是官方术语,但这就是那个人的意思。

于 2013-09-22T12:18:59.780 回答
1

未捕获的异常将导致应用程序崩溃。您可以订阅 AppDomain.UnhandeledException 事件以获取有关此类情况的通知,在日志中写入一些消息等

但是,您无法阻止应用程序在该处理程序中崩溃,因为将没有可以继续执行的点。

于 2013-09-22T12:18:02.523 回答