Error handling in ASP.NET

Posted by Beach Musician, 09-08-2008, 11:49 AM
I'm trying to help a colleague who wants to do error handling for his ASP.NET website. I was reading this from 15seconds.com about ASP.NET: Will this work even if debug = false? Are there any tutorials on the web you can direct me to that really go in depth on this? Thanks for your help!

Posted by Beach Musician, 09-10-2008, 01:51 PM
P.S. I did try the code on 15seconds.com, but couldn't get it to work even with debug=true... Sorry I didn't mention that...! So after I couldn't get that code to work, I continued doing research to try to find out if it is possible to get the line number from an exception even when debug = false. There is a lot of conflicting stuff out there, and this is something I'm trying to do to help someone else. So any help would be greatly appreciated!!!

Posted by RPK_MN1, 09-13-2008, 03:36 PM
why do you need the line number? The exception message should tell you pretty clearly what the type of exception was. Just use the geneated code that ASP.net autocompletes for you. when you type "Try" and hit enter, it generates the "Catch" statement -- ie. "Catch ex as exception". if you look at "ex.message" it will tell you very clearly what the error message is, be it an invalid cast, overflow, db connection error etc. if the exception you've caught is something to do with a sql query, it will even tell you what the syntax error was in your query. typically, what I do is catch the error in this manner: private function ExcCheck() as boolean try ... int i = 'a' 'this will throw an exception (actually, i don't suppose it would compile, but anyway) catch ex as exception me.lblStatus.Text = "Error occurred in ExcCheck function: " & ex.message end function by putting a label called "lblStatus" on your page, you will get a message telling you what method caused the error and what the exact error was -- invalid cast in this case. worst case scenario, you can put a breakpoint at the beginning of your method and step through it line-by-line to find your error.

Was this answer helpful?

 Print this Article

Also Read

Compromised???

Posted by Chinese Democracy, 04-20-2009, 12:01 PMIt appears that one new sign-up on a shared...

date --utc on VPS ?

Posted by enz0, 06-17-2008, 03:07 PMHi all, I just created a VPS with Empire VPS. I'm...

Possible Hard Drive Failure Soon

Posted by threemints, 04-19-2009, 05:03 PMI just received: [cPanel smartcheck] Possible Hard...

Wordpress Avatar based on username

Posted by mfwl, 02-10-2011, 05:43 AMI am trying to add a wordpress avatar based on the username,...

cobol Class need help with code.

Posted by slayer1189, 10-24-2012, 11:56 AMI am trying to have the program sort through the input...