Elmah not catching WebConfigurationManager.AppSettings[""].ToString() Exception in C#

145 views Asked by At

I have the following code;

string sPath = WebConfigurationManager.AppSettings["FilePath"].ToString();

I found that the App Setting 'FilePath' hasn't been declared (doesn't exist), and I'm getting the exception "Object reference not set to an instance of an object", on this line of code.

However I have Elmah working in my project, but it isn't catching and logging this exception, but is logging all other exceptions.

Where am I going wrong and why isn't this exception being catch. I was of the understanding Elmah would catch all unhandled exceptions.

UPDATE:

I added a try catch around the call, and it does catch the exception.

try
{
    string sPath = WebConfigurationManager.AppSettings["FilePath"].ToString();
}
catch
{
    ...
}

Some I'm confused why Elmah is not logging and catching the exception.

0

There are 0 answers