Forum Moderators: open
One thing I have never been able to wrap my head around is Error Handling.
Is there a way to set up some easy code to do this? I've been told it's fairly simple.
If an error comes up, I need to stop the process and display a proper error message. After I set this up, I may even set some script in there so that I get an email about the error, but I need to take small steps first.
What are the advantages of ON ERROR RESUME? When shouldn't I use it (if at all)?
Thanks in advance!
I dont think theres any standard way of error handling in VBScript, its really about handling errors specific to the app.
Generally I use openDB() and executeSQL() functions that returns true or false, so errors can be handled in the main script.
To stop execution, (for example on submitting forms) I use a sub :
errMsg( errType, badValue )
that calls response.end after display an error message using a select case on errType.
For this I wrote an enum of expected input error types like invaidDate, notAnInt, isNull etc. just to decouple error handling from the main job of programmin.
I would use ON ERROR RESUME NEXT in production code, to make sure any objects memory is released . If you use it, you could follow every line that can potentially error with something like this :
if err.number <> 0
errMsg( err.number)
err.clear
end if
Hope this helps.
For asp i would advise writing a simple custom 404 message page and having IIS redirect to it. Then loop through the forms collection, the session collection and the server variables and have the contents emailed to you. You would be amazed at the thousands of errors that can get generated and you never know about them.