Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Handling

Status
Not open for further replies.

PureDevelopers

IS-IT--Management
Aug 25, 2006
18
US
I wrote a custom error handler class that is supposed to insert the error info into the database when an error occurs, but when I call it from a catch block all I get is the generic error page and no insert. Is there something I need else I need to do in addition to adding a try block to trap errrors?

try
{
//throwing error on purpose
int i = null;
}
catch (Exception ex)
{
ErrorHandler.HandleError(ex, "Sorry, we are experiencing a problem with our photo galleries. Our site administrator has been notified.");
}


The ErrorHandler.HandleError method is being ignored, and the page is just throwing an error. I thought the whole idea was to trap the error and handle it. Do I have to clear the error or something. I don't want the user to see the error page. I want to insert the error info into the database and send the user to a friendly page.
 
I do something similar when trapping my errors - I call a method which sends an email to the System Administrator and then redirects the user to an 'error' web page. My method doesn't get ignored.

So based on what you've posted, I would say that you're going about this in the right way, so maybe there's a problem elsewhere in your code. Why not post the whole lot and see if someone spots anything.
 
You know, I never thought of this, but maybe the code that does the insert is causing the error. I will look at that first and then revisit. Thanks for the reply
 
What kind of error is it that get's thrown?

Threading errors in particular do weird things to attempts to catch them.

Brian Begy
BugSentry - Automatic error reporting
 
I haven't looked at it again yet. Been working on other parts of the app. My guess is that I have an error in the error handler related to the insert of the error. I will post more later today when I get a chance to go over it in more detail.
 
OK, here is the error:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0037: Cannot convert null to 'int' because it is a value type

Source Error:



Line 17: {
Line 18: //throwing error on purpose
Line 19: int i = null;
Line 20: }
Line 21: catch (Exception ex)


Source File: d:\_Web\GoDaddy_MissionBeachVolleyball.com\Default.aspx.cs Line: 19


It doesn't appear that it is being trapped or caught. The error handler code doesn't even get invoked. It just chokes on the invalid assignment.

Is there something specific I need to do in debug mode to get it to work?
I can't even step over or out. My only options are to stop or restart debugging.

this is what I have in the web.config:
<authentication mode="Forms"/>
<customErrors mode="Off"/>
I am clueless why I can't trap errors. By the way I am using Visual Web Developer, not Studio.
 
Its a compiler error. Your handler isn't executing because none of your code is executing. Can you build it on your workstation? (I'm not familiar with VWD)

Brian Begy
BugSentry - Automatic error reporting
 
Hi,

Line 18: //throwing error on purpose
Line 19: int i = null;

Why use this bad way to THROW an exception?

Also for better results visit and post in forum855
 
OK, I finally figured it out. The error I was creating was a compile error. I was just trying to test my error handler, but if the code can't compile, it can't be trapped. I created a different error (runtime), and it worked fine.

try
{
int i = Convert.ToInt32(this.lblError.Text);
}
catch (Exception ex)
{
lblError.Text = ex.Source.ToString();
ErrorHandler.HandleError(ex, "Sorry, we are experiencing a problem with our photo galleries. Our site administrator has been notified.");
}

I created a label with no text and used the following code. The compiler doesn't know that the label text is invalid so the code builds, but throws a runtime error and my error handler handles it perfectly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top