Results 1 to 10 of 52

Thread: Resume On Error GoTo 0 -1 GoTo Error Handling Statements Runtime VBA Err Handling ORNeRe GoRoT N0Nula 1

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    "Pseudo" Default VBA Error handling


    Codes to mimic VBA Default Error handling.
    The code below, using user define VBA error handling, is an approximation to part of the VBA Default Error handling. ( The line numbers are just added to help the further explanations: they are not needed for these codes. )
    Run the code.
    We can, to a first approximation say that the _ OK _ Button which appears in the pop up message box is doing similar to the _ Beenden/Stop _ Button from Default VBA Error handling.
    Code:
    ' -1    ' No Exception state before the code is run ( Ending a code clears any exception )
    Sub PseudoVBADefaultErrorhandlingPartial()
    0
    1 On Error GoTo ErrHndler ' '_- Hang hook on chain of events that signify to go to call back procedure when chain is waggled by error erection
    Dim Db As Double
    ' Coding
     Let Db = 1 / 0 '           '_- When the error occurs, the Exception software has the code from ErrHndler included in it
    ' Other Coding. In the case of an error this will never be done
    GoTo AfterErrHndler
    ErrHndler: ' =========================== ' Call back procedure. Code to be hooked on to Exception software.    User defined  pseudo VBA Error handling
     MsgBox prompt:="Laufzeitfehler '" & Err.Number & "':" & vbCr & vbLf & Err.Description & "                      ", Title:="Microsoft Visual Basic": Debug.Print "Laufzeitfehler '" & Err.Number & "':" & vbCrLf & Err.Description & "                      " ' From VB Editor , hit  Ctrl+g  to display the Immediate Window   ---      Laufzeitfehler '11': Division durch Null     Runtime Error '11': division with zero
    '
    Exit Sub ' This will clear the exception state. No exception state once code is Ended
    AfterErrHndler: '=======================
    'You never get here
    ' Other Coding ' In the case of an error this will never be done
    End Sub ' This will clear the exception state. No exception state once code is Ended
    ' -1 Sub PseudoVBADefaultErrorhandlingPartialSimplified() On Error GoTo ErrHndler ' Dim Db As Double ' Coding Let Db = 1 / 0 ' When the error occurs, the Exception software has the code from ErrHndler included in it ' Other Coding. In the case of an error this will never be done Exit Sub ErrHndler: ' Error handling code section MsgBox prompt:="Laufzeitfehler '" & Err.Number & "':" & vbCr & vbLf & Err.Description & "" End Sub
    Error handling code section
    Just to clarify what I am doing here: I am using error handling techniques to make an error handler similar to the default VBA error handler. This is just by way of a learning exercise to get familiar with VBA error situations in general.
    The code section as indicated within ==== is typically referred to as the Error handling code section. In this case the code carried out as part of the Exception Coding is within that section. But it need not be. That referral can be meant to include code lines such as GoTo LabelOrLineNumber or also the execution of any of the three resumes, which effectively bring the normal code back into action. So the term error handling code section is not clearly defined.
    To a first approximation the error handling code section is the code section as indicated within ====

    The error handling code section need not be , but often is, at the end of the main code. In either case it is necessary to organise that in normal code progressing when no error occurs, that error handling code section will be bypassed.
    If, in the last code the error handling code section were at the end, then the label AfterErrHndler: could be omitted, and the Goto AfterErrHndler replaced with Exit Sub

    Here the same code again in a more typically seen simplified form
    Code:
    ' -1
    Sub PseudoVBADefaultErrorhandlingPartialSimplified() '                                                                                       https://excelfox.com/forum/showthread.php/2239-Resume-On-Error-GoTo-0-1-GoTo-Error-Handling-Statements-Runtime-VBA-Err-Handling-ORNeRe-GoRoT-N0Nula-1?p=10551&viewfull=1#post10551
    On Error GoTo ErrHndler '
    Dim Db As Double
    ' Coding
     Let Db = 1 / 0 ' When the error occurs, the Exception software has the code from ErrHndler included in it
    ' Other Coding. In the case of an error this will never be done
    Exit Sub
    ErrHndler: ' Error handling code section
     MsgBox prompt:="Laufzeitfehler '" & Err.Number & "':" & vbCr & vbLf & Err.Description & ""
    End Sub
    Last edited by DocAElstein; 03-21-2023 at 05:53 PM.

Similar Threads

  1. Replies: 8
    Last Post: 09-01-2015, 01:50 AM
  2. Difference Between 'On Error GoTo 0' And 'On Error GoTo -1'
    By Transformer in forum Familiar with Commands and Formulas
    Replies: 7
    Last Post: 07-02-2015, 04:07 PM
  3. Replies: 2
    Last Post: 05-14-2013, 01:02 AM
  4. Runtime Error 481 invalid figure when PNG
    By Tony in forum Excel Help
    Replies: 0
    Last Post: 02-12-2013, 12:59 AM
  5. Replies: 10
    Last Post: 04-07-2012, 05:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •