未捕获的异常确定源 [英] Uncaught exception determine source

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

问题描述

最近我找到了一个异常行由行的源代码

 尝试
{
    的Debug.WriteLine(视图助手之前comObj.Send());
    comObj.Send(); //一个很老的COM组件
    的Debug.WriteLine(视图助手后comObj.Send());
}
赶上(例外前)
{
    的Debug.WriteLine(视图助手comObj.Send+ Ex.Message);
}
 

comObj.Send()被抛出异常
唯一的例外崩溃的应用程序
但它不是夹在上面尝试捕捉
我不得不打破在Visual Studio中所有的异常,并没有打破该行
它被夹在一个全球性的错误处理程序App_DispatcherUnhandledException
如果设置了e.Handled = TRUE;它只是抛出了很多次,仍然崩溃的应用程序
唯一的例外没有透露有关源产品资讯 我发现源的唯一方法是那些之前和之后的调试语句
该异常被扔在百分之一通话所以这是很难跟踪

有没有一个更好更快的方法来查找异常的根源?
它有没有办法回踩所谓的最后一行?

在后的网站,我应该把重点放在了COM组件。

解决方案

当我怀疑异常正在从本地code抛出,启用的非托管code调试。从 MSDN

  

要启用非托管code调试

     
      
  1. 通过在Solution Explorer中选择一个项目,在项目菜单上,单击属性。

  2.   
  3. 点击调试选项卡。

  4.   
  5. 选择启用非托管code调试复选框。

  6.   

这会降低性能,以便将其关闭时没有调试本地组件。

我还对所有异常打破第一,但你提到你这样做,所以非托管调试将是我的下一个步骤。

I recently tracked down the source of an exception line by line

Try
{
    Debug.WriteLine("ViewHelper before comObj.Send() ");
    comObj.Send();   // a very old com component
    Debug.WriteLine("ViewHelper after  comObj.Send() ");
}
Catch (Exception Ex)
{
    Debug.WriteLine("ViewHelper comObj.Send " + Ex.Message);    
}

comObj.Send() was throwing an exception
The exception crashes the app
But it was not caught in the above Try Catch
I had break on all Exceptions in Visual Studio and it was not breaking on that line
It was caught in a global error handler App_DispatcherUnhandledException
If I set e.Handled = true; it is just thrown many times and still crashes the app
The exception gave no information about the source
The only way I found the source was by those before and after debug statements
The exception was thrown in one in a hundred calls so it was hard to track

Was there a better faster way to find the source of the Exception?
It there a way to step back to the last line called?

In hind site I should have focused on the COM components.

解决方案

When I suspect that exceptions are being thrown from native code, I enable debugging of unmanaged code. From MSDN:

To enable debugging of unmanaged code

  1. With a project selected in Solution Explorer, on the Project menu, click Properties.

  2. Click the Debug tab.

  3. Select the Enable unmanaged code debugging check box.

This can slow performance so turn it off when not debugging native components.

I'd also break on all exceptions first but you mentioned that you did that, so unmanaged debugging would be the next step for me.

这篇关于未捕获的异常确定源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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