Navi

应用程序捕获未处理异常的方法

项目中提示未处理异常,无法捕获。提示信息如下:
“Application has generated an exception that could not be handled”
解决方法如下:
 1public static void Main()   
 2  
 3     AppDomain currentDomain =   AppDomain.CurrentDomain; 
 4     currentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptions); 
 5           
 6  }
 
 7
 8private static void UnhandledExceptions(object sender, UnhandledExceptionEventArgs args) 
 9  
10     Exception e = (Exception)   args.ExceptionObject; 
11     //try to trace the stack here and see   what,when and why. 
12  }
这就可以在 UnhandledExceptions方法中捕获到未处理的异常,并做相应的处理。
注:
AppDomain: 一个应用程序在其中执行的独立环境。

posted on 2010-08-20 09:07 Navi 阅读(216) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: