views:

67

answers:

1

Hi All,

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 instance; 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

+2  A: 

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
driis
Thank you for your response. Just after executing the stored procedure (in the ASP code), the following line of code appears: "If Err.Number <> 0 Then," and then some error handling code. My suspicion is that the asp.dll cannot catch and handle .NET exceptions. Do you have any other suggestions? Thanks.
Tyler
If the Classic ASP error mechanism kicks in and shows you an ASP error, then you should be able to handle it like that. If not, you might be doing something else ... Perhaps try to post some example code ?
driis
I haven't written anything in ASP in a long time. You were correct; I was handling errors incorrectly. Thank you!
Tyler