Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is try-catch like error handling possible in ASP Classic?

What options are there in ASP Classic for error handling?

For example:

I'm using the Mail.SendMail function but when switching on the testing server it doesn't work, which is normal. I want to test if mailing is possible, if not then continue and/or show a message.

Any ideas?

like image 683
Sander Versluys Avatar asked Jan 23 '09 11:01

Sander Versluys


People also ask

Can we handle error using try-catch?

The try statement defines a code block to run (to try). The catch statement defines a code block to handle any error. The finally statement defines a code block to run regardless of the result. The throw statement defines a custom error.

How do I use try-catch in classic ASP?

The worst part of Classic ASP in VBScript is Error Handling. You need to type “on error resume next”, then, check, on every line, check if the previous one generates an error using [If Err. Number <> 0 then …].

What is try-catch error handling?

What Does Try/Catch Block Mean? "Try" and "catch" are keywords that represent the handling of exceptions due to data or coding errors during program execution. A try block is the block of code in which exceptions occur. A catch block catches and handles try block exceptions.

Do try-catch swift error?

Handling Errors Using Do-Catch. You use a do - catch statement to handle errors by running a block of code. If an error is thrown by the code in the do clause, it's matched against the catch clauses to determine which one of them can handle the error.


1 Answers

There are two approaches, you can code in JScript or VBScript which do have the construct or you can fudge it in your code.

Using JScript you'd use the following type of construct:

<script language="jscript" runat="server"> try  {     tryStatements } catch(exception) {     catchStatements } finally {     finallyStatements } </script> 

In your ASP code you fudge it by using on error resume next at the point you'd have a try and checking err.Number at the point of a catch like:

<% ' Turn off error Handling On Error Resume Next   'Code here that you want to catch errors from  ' Error Handler If Err.Number <> 0 Then    ' Error Occurred - Trap it    On Error Goto 0 ' Turn error handling back on for errors in your handling block    ' Code to cope with the error here End If On Error Goto 0 ' Reset error handling.  %> 
like image 168
Wolfwyrd Avatar answered Oct 07 '22 22:10

Wolfwyrd