Handle .NET exceptions within Classic ASP pages
I am making MSSQL stored procedure CLR calls from ASP pages. When an exception occurs, it is logged and then rethrown. In this scenario I need to be able to handle the exception (if possible) in the ASP page. Note that I cannot move away from classic ASP in this instan开发者_如何学Cce; I am stuck within a legacy system for this project. Please let me know if you know of a way to handle the exceptions in classic ASP. I appreciate the help!
Thanks, Tyler
The code language of classic ASP is VBScript, so you have to make do with the error handling capabilities of that language, by using the "On Error ..." construct. You need to decide on whether to make a general error handler or insert some specific error handling logic for the SQL calls.
These are your options for error handling:
On Error Goto 0 ' Turns off error trapping. This is most likely what you got now
On Error Resume Next ' In case of error, simply execute next statement. Not recommended !
On Error Goto <label> ' Go to the specified label on an Error.
If you use On Error Goto ..., The Err object will contain error information. This means you should be able to write somehting like:
On Error Goto errorHandler
' Your code here.
errorHandler:
' Handle the error somehow. Perhaps log it and redirect to a prettier error page.
Response.Write Err.Number
Response.Write Err.Description
精彩评论