Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Classic ASP: On Error Stop

I have an ASP page that runs two SQL insert statements at the beginning before displaying the page. In the event I get a primary key conflict (ie. the inserts have already ran that day), I just want to carry on.

My code is basically:

on error resume next
' insert statements

Once the statements have been executed, I would like to resume the default error behaviour, where the page dies with an error message.

Is there a command, like "on error stop", or "on error die", or "on error default", or something to reset the error handling to it's default behaviour?

like image 565
dangowans Avatar asked Dec 12 '25 12:12

dangowans


1 Answers

If you want it to throw an error without going to any sort of custom error handler, use:

On Error GoTo 0

You can test it out in a quick sample ASP page with the following:

<% Language="VBScript" %>

<% Response.Write "Hello" %>

<% On Error Resume Next
   Dim rs
   SET rs = Server.CreateObject("ADODB.RecordSet")
   
   'On Error Goto 0
   rs.MoveNext

%>

<% Response.Write "Bye" %>

With On Error Goto 0 commented out, Bye will get written as normal. With On Error Goto 0 enabled, you'll get the following error:

ADODB.Recordset error '800a0e78'

Operation is not allowed when the object is closed.

like image 73
LittleBobbyTables - Au Revoir Avatar answered Dec 14 '25 00:12

LittleBobbyTables - Au Revoir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!