I have a statement inside a try/catch block, but the exception is not getting caught. Can anyone explain?
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 139:                try
Line 140:                {
Line 141:                    return (int)Session["SelectedLeadID"];
Line 142:                }
Line 143:                catch (Exception ex)
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.
That catch block should catch the exception, but make sure there's no re-throwing in there.
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 :)
I suspect you're going to need to add more detail - that isn't reproducible just from your code. In particular (as already noted) we'd need to see inside the catch, and verify that the exception is actually being thrown from inside the try and not somewhere else.
Other possibilities:
Dispose() that is getting called (using etc)Exception, but some other objectIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With