Windows 窗体应用程序中未处理的异常
我有一个 Windows 窗体应用程序。它使用 Assembly.LoadFile 加载扩展名为 .Plugin.dll 的程序集。这些“插件”之一调用另一个程序集 dll。该 dll 最终会抛出 ValidationException 异常。引发异常的方法位于继承自 IDataErrorInfo 的类中。此类是包含在 Linq to SQL 类 (.dbml) 中的类。在“插件”中,我调用 DataContext.SubmitChanges。它包含在 try/catch 块中。这会导致我的业务逻辑在 OnValidate 重写中提交到数据库之前验证数据。我看到的结果是,在引发 ValidationExeption 后,调试器在 OnValidate 方法的底部停止,表明发生了未处理的异常。如果我继续运行该应用程序,我的 catch 块就会被执行。这就是我首先想要的,但是为什么当它真正被处理时我会得到一个未处理的异常?
I have a Windows Forms application. It loads assemblies with the extension .Plugin.dll with Assembly.LoadFile. One of these "plugins" calls into another assembly dll. That dll eventually throws a ValidationException exception. The method that throws the exception is in a class that inherits from IDataErrorInfo. This class is a class that is contained in a Linq to SQL class (.dbml). In the "plugin" I call DataContext.SubmitChanges. This is wrapped in a try/catch block. This causes my business logic to validate the data before submitting to the database in the OnValidate override. The result that I see is that after the ValidationExeption is thrown, the debugger stops at the bottom of the OnValidate method indicating that an unhandled exception has occured. If I continue to run the app my catch block is executed. That is what I wanted in the first place, but why am i getting an unhandled exception when it truly is handled?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我 99% 确定导致此问题的“真正”异常确实未处理 - 这是调试器首先告诉您的内容,他通常是正确的。
当您继续在 VS 中运行该应用程序之后,它是实际上并不是当您从调试器中执行 exe 时会发生什么。事实上,调试器首先通知您未处理的异常,然后继续一些待处理的逻辑(如果有)(这就是您看到 ValidationException 错误的原因)。但未处理的异常仍然存在。我不太清楚这种行为的细节和原因,但我多次注意到这一点。
在识别出未处理异常后,您必须在抛出未处理异常的精确位置捕获精确的错误。
也许发布您的代码示例会有所帮助。
I am 99% sure your "real" exception causing this is indeed unhandled -this is what the Debugger tells you at first place, and he is generally right.
When you continue to run the App in VS after that, it is not actually what would happen when you will execute your exe out of the debugger. In fact, the debugger notifies you first of the unhandled exception, and then continues some pending logic if any (that's why you see you ValidationException error). But the unhandled exception is still there. I don't exactly know the details and causes of this behavior, but I noticed this many times.
You have to catch the precise error at the precise place where the unhandledexception is thrown after you identify it.
Maybe posting your code sample would help.
首先,插件是否在同一个AppDomain中?
其次,听起来好像您的调试器“抛出异常时中断”而不是“用户未处理异常时中断”。
在 VS.NET 中,转到“调试”-->“调试”异常...
展开“公共语言运行时异常”节点并查看是否有任何被勾选。
Firstly, is the plugin in the same AppDomain?
Secondly, it sounds to be like you have your debugger to "Break when exception is thrown" rather than "Break when exception is user-unhandled".
In VS.NET, go to Debug --> Exceptions...
Expand the "Common Language Runtime Exceptions" node and see if any are ticked.