Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Dealing with exceptions
Old 02-19-2007, 04:18 PM Dealing with exceptions
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
void Page_Load(object sender, EventArgs e) {
try {
// Do something ...
} catch(Exception ex) {
string msg = "<h3>" + ex.Message + "</h3>";
msg += ex.StackTrace.Replace(" at ", "<br>");

if(ex.InnerException != null) {
msg += "<br><br><b>Caused By:</b><br><br><h3>" + ex.InnerExeption.Message + "</h3>";
msg += ex.InnerException.StackTrace.Replace(" at ", "<br>");
}
// Now log msg to the database, and it will be rendered properly for an administrator who can view an online website health report

}
}
Learning Newbie is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-19-2007, 04:24 PM Re: Dealing with exceptions
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Sorry dude...this looks helpful but someone might get confused by this, so forgive my anal nature:
Code:
msg += "<br><br><b>Caused By:</b><br><br><h3>" + ex.InnerException.Message + "</h3>";
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 02-20-2007, 04:14 PM Re: Dealing with exceptions
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Good catch, thanks! I knew I should have pulled up the IDE instead of just typing that in here.

Anybody else can use the code Adam and I pieced together in your systems. Users hate errors, and expect you to fix them in a hurry. Under the defaults if you're running ASP.NET it will only show what caused the error if you're using the server to surf to that page and get an error - from a different machine you get a page that says "Oops!" But the cause of the error is available in these variables, except they use line breaks, which get ignored when you render them with html. So we simply force a <br> where you would expect a line break in the report, to make it easier to read.

For extra credit, you could set this to email you whenever an error happens, with the details of what caused it. Then you might be able to fix some of them before your users even complain.
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Dealing with exceptions
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12800 seconds with 12 queries