Classic Asp On Error Goto Label
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the classic asp on error goto 0 company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions on error goto label vba Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million vbscript on error goto label programmers, just like you, helping each other. Join them; it only takes a minute: Sign up VBScript — Using error handling up vote 58 down vote favorite 13 I want to use VBScript to catch errors vbscript on error goto label example and log them (ie on error "log something") then resume the next line of the script. For example, On Error Resume Next 'Do Step 1 'Do Step 2 'Do Step 3 When an error occurs on step 1, I want it to log that error (or perform other custom functions with it) then resume at step 2. Is this possible? and how can I implement it? EDIT: Can I do something like this? On
Asp On Error Display Message
Error Resume myErrCatch 'Do step 1 'Do step 2 'Do step 3 myErrCatch: 'log error Resume Next vbscript error-handling share|improve this question edited Oct 1 '08 at 14:13 asked Oct 1 '08 at 14:04 apandit 2,50111831 1 Dylan's response is about as good as VB gets in the Error handling department. This is why I always used Javascript when I could get away with it. –wcm Oct 1 '08 at 14:23 add a comment| 2 Answers 2 active oldest votes up vote 102 down vote accepted VBScript has no notion of throwing or catching exceptions, but the runtime provides a global Err object that contains the reuslts of the last operation performed. You have to explicitly check whether the Err.Number property is non-zero after each operation. On Error Resume Next DoStep1 If Err.Number <> 0 Then WScript.Echo "Error in DoStep1: " & Err.Description Err.Clear End If DoStep2 If Err.Number <> 0 Then WScript.Echo "Error in DoStop2:" & Err.Description Err.Clear End If 'If you no longer want to continue following an error after that block's completed, 'call this. On Error Goto 0 The "On Error Goto [label]" syntax is supported by Visual Basic and Visual Basic for Applications (VBA), but VBScript doesn't support this language feature so you have to use On Error Resume Next as described abov
Problem with "on error goto label" code If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register
Asp On Error Resume Next
before you can post: click the register link above to proceed. To on error goto 0 start viewing messages, select the forum that you want to visit from the selection below. Results 1 to 3 of 3 Thread: Problem with "on error goto label" code Tweet Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch http://stackoverflow.com/questions/157747/vbscript-using-error-handling to Threaded Mode 03-21-2001,12:36 PM #1 Tim Guest Problem with "on error goto label" code I'm trying to do the following in an ASP form: on error goto errhandler errhandler:
> > errhandler: >
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference https://msdn.microsoft.com/en-us/library/aa266173(v=vs.60).aspx Dev centers Retired content Samples We’re sorry. The content you requested has https://msdn.microsoft.com/en-us/library/ms675540(v=vs.85).aspx been removed. You’ll be auto redirected in 1 second. Language Reference Statements I-P I-P On Error Statement On Error Statement On Error Statement If...Then...Else Statement Implements Statement Input # Statement Kill Statement Let Statement Line Input # Statement Load Statement Lock, Unlock Statements LSet Statement Mid Statement MkDir Statement on error Name Statement On Error Statement On...GoSub, On...GoTo Statements Open Statement Option Base Statement Option Compare Statement Option Explicit Statement Option Private Statement Print # Statement Private Statement Property Get Statement Property Let Statement Property Set Statement Public Statement Put Statement TOC Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. This documentation on error goto is archived and is not being maintained. Visual Basic for Applications Reference Visual Studio 6.0 On Error Statement See Also Example Specifics Enables an error-handling routine and specifies the location of the routine within a procedure; can also be used to disable an error-handling routine. Syntax On Error GoTo line On Error Resume Next On Error GoTo 0 The On Error statement syntax can have any of the following forms: Statement Description On Error GoTo line Enables the error-handling routine that starts at line specified in the required line argument. The line argument is any line label or line number. If a run-time error occurs, control branches to line, making the error handler active. The specified line must be in the same procedure as the On Error statement; otherwise, a compile-time error occurs. On Error Resume Next Specifies that when a run-time error occurs, control goes to the statement immediately following the statement where the error occurred where execution continues. Use this form rather than On Error GoTo when accessing objects. On Error GoTo 0 Disables any enabled error handler in the current proced
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev centers Retired content Samples We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. ActiveX Data Objects (ADO) Error Handling Handling Errors In Other Languages Handling Errors In Other Languages Handling Errors in VBScript Handling Errors in VBScript Handling Errors in VBScript Handling Errors in VBScript Handling Errors in Visual C++ Handline Errors in Visual J++ Handling Errors in JScript TOC Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. This documentation is archived and is not being maintained. Handling Errors in VBScript There is little difference between the methods used in Visual Basic and those used with VBScript. The primary difference is that VBScript does not support the concept of error handling by continuing execution at a label. In other words, you cannot use On Error GoTo in VBScript. Instead, use On Error Resume Next and then check both Err.Number and the Count property of the Errors collection, as shown in the following example: Copy
Error Handling Example (VBScript)
<% Dim cnn1 Dim errLoop Dim strError On Error Resume Next ' Intentionally trigger an error. Set cnn1 = Server.CreateObject("ADODB.Connection") cnn1.Open "nothing" If cnn1.Errors.Count > 0 Then ' Enumerate Errors collection and display ' properties of each Error object. For Each errLoop In cnn1.Errors strError = "Error #" & errLoop.Number & "" & _ " " & errLoop.Description & "
" & _ " (Source: " & errLoop.Source & ")"