Try/Catch 块未捕获异常 [英] Try/Catch block not catching Exception

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

问题描述

我在 try/catch 块中有一条语句,但未捕获异常.谁能解释一下?

I have a statement inside a try/catch block, but the exception is not getting caught. Can anyone explain?

异常详情:System.NullReferenceException: 对象引用未设置到一个实例对象.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

源错误:

Line 139:                try
Line 140:                {
Line 141:                    return (int)Session["SelectedLeadID"];
Line 142:                }
Line 143:                catch (Exception ex)

更新这是一个 ASP.NET 应用程序.在 catch 块中,抛出了一个新的异常.您看到的代码就是显示在 ASP.NET 错误页面上的代码.

Update This is an ASP.NET application. In the catch block, a new exception is thrown. The code you see is what is displayed on the ASP.NET error page.

推荐答案

那个 catch 块应该捕获异常,但要确保没有重新抛出.

That catch block should catch the exception, but make sure there's no re-throwing in there.

另一个小评论:我已经被 VS 欺骗了很多次,因为它在调试模式下运行时会因为这样的异常而中断.尝试简单地按继续"或F5",看看您的应用程序是否仍然无法运行:)

Another small comment: I've been tricked quite a few times by VS, cause it breaks on exceptions like that while running in debug-mode. Try to simply press 'continue' or 'F5' and see if your application doesn't work anyway :)

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

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