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

Php as CGI or not.

Posted by Vinayak_Sharma, 01-13-2008, 08:37 AMOk I am configuring a fresh/new WHM/cPanel server...

Multiple sites running off same code

Posted by AimyThomas, 10-25-2012, 11:09 PMI m interested in making multiple websites, all with...

Websites hacked, can't find the file

Posted by crk91, 04-20-2009, 09:30 PMI don't know how this happened but someone got into my VPS...

Question for PayPal programmer expert!

Posted by pronet-hq, 09-11-2008, 11:30 AMI am creating a website that allows sellers to offer...

frequent rebooting - what can cause this?

Posted by Premier, 07-14-2007, 12:28 AMI have a server that is monitored with a system that...