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

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    Post #10 on page #1 https://excelfox.com/forum/showthrea...ll=1#post10558






    Error Handling statement Resumes
    On Error Resume Next

    The next posts will look at the second main Error handling statement , On Error Resume Next .
    Every time I look at this, I come up with a slightly different idea. To some extent I may be going back and forwards, fluctuating a bit, bit on average I am perfecting the understanding a bit better.
    If I try, as I have done in the past, to discus the more fundamental general idea of the Resume .
    And build on that, to derive user defined error handlers that works in a similar way, things don’t come outs quite as logically as one might expect. .

    In my opinion the whole VBA error handling is an unintuitive mess. In the unlikely event that you have read and understood most of my previous ramblings, then a couple logical conclusion might be the following:

    _ We might reasonably guess that there is no On Error Resume
    This is because that would imply that at an error the code tries again. And again. And again And again. And again.. … Conceivable there might be a situation where that might work if some external influence meant that the code line erroring suddenly didn't. But that is unlikely. More likely is that having such an option would cause the attempt at an infinite loop or retrying.
    In fact that assumption is correct. There is no On Error Resume

    _ We might reasonably guess that there might be a On Error Resume LabelOrLineNumber
    That would be a reasonable thing to do. But there isn’t. Perhaps this should slightly spark our suspicions.

    Indeed we find the On Error Resume Next is not quite doing _ On Error ……… then …. Resume Next. Almost it does. It does both
    _ carry on after the line causing the error
    , and
    _ it appears to not be in The State of Exception
    But here is the oddity. The error object, Err , is not cleared and so can still be used to tell us what error did occur , (and the Erl() also tells us the last line number that errored )




    On Error Resume Next is very commonly used ( badly in the opinion of most professionals) to just keep a coding going despite any errors
    This simplest use is shown in the next macro. All errors are ignored.

    Code:
    Sub OnErrorResumeNext1()  '  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=10559&viewfull=1#post10559
    0 Dim Ex As Double
    10 On Error Resume Next
    
    20 Let Ex = 1 / 0
    30 MsgBox prompt:=Err.Description & ",  at line number" & Erl(): Debug.Print Err.Description & ",  at line number" & Erl()
    
    40 Let Ex = 1 / 0
    50 MsgBox prompt:=Err.Description & ",  at line number" & Erl(): Debug.Print Err.Description & ",  at line number" & Erl()
    End Sub
    '
    The output is like
    Division durch Null, at line number20
    Division durch Null, at line number40
    Last edited by DocAElstein; 03-23-2023 at 11:41 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
  •