捕捉未处理的异常编辑器 [英] Catch unhandled exceptions from editor

查看:265
本文介绍了捕捉未处理的异常编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用 MEF 内我们的WPF应用程序(MVVM),以使嵌入外部编辑器。在我们主视图中某些时候就是编辑器将被放置在一个内容元素。

We are using MEF within our WPF application (MVVM) to embedd external editors. At some point in our main view there is a content element where the editor is going to be placed in.

现在我们想赶上从编辑任何未处理的异常和然后重新装入编辑器。我发现的唯一的事情就是用 DispatcherUnhandledException 应用类。从那里,我会以某种方式到达主视图编辑器,并告诉它重新加载坠毁编辑器。

Now we would like to catch any unhandled exception from that editor and then reload the editor. The only thing I have found is to use DispatcherUnhandledException from the Application class. From there I would have to somehow reach the main view editor and tell it to reload the crashed editor.

我在想,如果有一个低级别的点,其中我可以捕获异常?有没有人有它的一些经验,可以帮助他在这里?

I was wondering if there is a "lower" level point, where I could catch the exception? Does anyone have some experience with it and could help he out here?

感谢

推荐答案

所以,我的回答是:你更好,如果你竟会不知道。当你得到一个未处理的异常,应用程序处于稳定状态不再。确切位置在哪里,你将恢复到?如果你的外部编辑器抛出一个损坏状态异常(例如一个Win32 SEH除外)像 AccessViolationException OutOfMemoryException异常?您的整个应用程序可能是在这一点上不确定的状态,所以进一步执行可能导致数据丢失和/或损坏。此外,CLR可能无法保证您的应用程序可以继续:

So my answer would be: you better don't if you even could. When you get an unhandled exception, your app is no longer in a stable state. Where exactly would you resume to? What if your external editor throws a Corrupted State Exception (e.g. a Win32 SEH exception) like an AccessViolationException or OutOfMemoryException? Your whole app might be in an undetermined state at that point, so further execution might lead to data loss and/or damage. Furthermore, the CLR might not guarantee that your app can continue:

SEH异常是由
引发的异常的不同类你的程序。一个程序,因为它试图
从空栈中弹出一个项目或试图打开一个文件,该文件并没有
可能存在引发异常。所有这些异常在
程序执行的情况下才有意义。 SEH例外情况请参阅您的
计划外的环境。不同于程序错误,一个SEH异常指示运行的过程
完整性可能被破坏。

SEH exceptions are a different class from those exceptions raised by your program. A program might raise an exception because it tried to pop an item from an empty stack or tried to open a file that didn't exist. All of these exceptions make sense in the context of your program's execution. SEH exceptions refer to a context outside of your program. Unlike program errors, an SEH exception indicates that the integrity of the runtime's process may have been compromised.

请阅读 SEH和CLR例外这里

下面是什么我不建议你这样做,而是你的信息:你可以防止你的应用程序通过更新您的的app.config 的文件中捕获未处理的异常后,关闭

Here is what I'm not suggesting you to do, but rather for your information: you could prevent your app from closing after catching an unhandled exception by updating your app.config file:

<runtime>
  <!-- the following setting prevents the host from closing when an unhandled exception is thrown -->
  <legacyUnhandledExceptionPolicy enabled="1" />
</runtime>



不过,由于微软的状态,如果忽略异常,应用程序可能会泄漏资源并放弃锁定。

But, as Microsoft states, if you ignore exceptions, the application may leak resources and abandon locks.

这篇关于捕捉未处理的异常编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆