1
votes

I do maintenance on a classic ASP website that basically has no error handling at all yet. So users see any error message that comes across... Instead, I would like my code to be able to catch any potential error and then fire off an email before redirecting the user to a more friendly error-page.

This website is rather large, and every webpage comes with the same include file at the beginning... So ideally, I would like to set an error handler from the beginning of this include file. I haven't had any luck finding a way to do this without having to go through every page individually having error handling happen at the end of the script... Is there a possible way to code something like this from the include file?:

' Include file contents:

Function MyHandler()

    'Code for triggering email goes here

    response.redirect "ErrorPage.asp"

End Function

On Error call MyHandler()

Thanks in advance!

1
The above code doesn't actually work... It's just a sample to show the basic idea of what I'm looking for. And I do fix errors as soon as I get word of them... but this would streamline that proccess. But seriously... With 2,500+ pages of code, and 40 hours a week of new developement and changes, there are always going to be at least a couple errors that slip through.justanotherguy
It's been a while since I used ASP. But I was thinking that the On Error Resume Next thing would be able to catch it. This SO answer might actually help: stackoverflow.com/questions/2202869/…durbnpoisn
Thanks, but that's not quite what I'm asking for. That is a typical error handler, but what I'm asking for is not typical. I'm asking if it's possible to call a function (or a sub) as soon as the first error occurs. This way I could plug it into the website very easily.justanotherguy
I think you still have the right idea. If you just plop that into one of the includes that's used sitewide, preferebly one that loads early, it should at least get a handle on things.durbnpoisn
Would configuring IIS to redirect users to an error page be an easier approach for you? dondraper.com/2011/01/…Ted

1 Answers

2
votes

I suggest to use Custom Error Pages in IIS (Web Server), if you have access to those. You can redirect different types of errors to different scripts if you like or point them all to a single one and have there the logic for all error codes.

You can catch common errors there and maybe redirect the user to a alternative page/site, or return a specific error message.. I would suggest to use the custom error page also to log the error and some information from the session (e.g. form submit data, query strings, referrer URLs, cookies etc.) in a database and/or send a notification email to some service account to identify specific issues that are occurring and then also have something to go on to actually fix the cause of many of the errors.