How to test for HttpException

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have this code in Global.asax, but it doesn't compile yet.
What am i doing wrong?
protected void Application_Error(Object sender, EventArgs e)
{
Exception objErr = Server.GetLastError().GetBaseException();
string msg = objErr.ToString();
if (objErr.GetType is HttpException)
{
// Need to bypass 404 errors
ErrNotify.LogError(msg);
}
else
{
ErrNotify.LogError(msg);
}
Server.ClearError();
}
 
Hi,

Arne said:
I have this code in Global.asax, but it doesn't compile yet.
What am i doing wrong?
protected void Application_Error(Object sender, EventArgs e)
{
Exception objErr = Server.GetLastError().GetBaseException();
string msg = objErr.ToString();

I would rather use

string msg = objErr.Message;
if (objErr.GetType is HttpException)

That should be

if ( objErr is HttpException )
{
// Need to bypass 404 errors
ErrNotify.LogError(msg);
}
else
{
ErrNotify.LogError(msg);

Did you notice that you do exactly the same in both cases?
}
Server.ClearError();
}

HTH,
Laurent
 
Hi Laurent,

I would rather use

string msg = objErr.Message;

Exception.ToString() provides details such as the StackTrace and the
StackTraces of the InnerException (recursively). Also, when deriving from
Exception you can override ToString to add more details about the exception
that the Message property doesn't provide.

So for error logging purposes, such as the OP's code, ToString is probably a
better choice.

<snip>
 
Hi Dave,

Dave said:
Hi Laurent,



Exception.ToString() provides details such as the StackTrace and the
StackTraces of the InnerException (recursively). Also, when deriving from
Exception you can override ToString to add more details about the exception
that the Message property doesn't provide.

So for error logging purposes, such as the OP's code, ToString is probably a
better choice.

<snip>

Yes, you're right. Don't know why, I was sure that the OP used msg to
display a warning to the user.

Greetings,
Laurent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top