Skip to content

"OnErroGoto -1" warning has a wrong description #5993

@interservices

Description

@interservices

Version 2.5.2.5906
OS: Microsoft Windows NT 10.0.22000.0, x64
Host Product: Microsoft Office x64
Host Version: 16.0.15225.20288
Host Executable: EXCEL.EXE


I am a (convinced) user of the (undocumented) instruction "On Error Goto -1" when I want complex inline error handlers, like this:

Sub example()
    Dim l&
    On Error GoTo errInLineHandler
    l = 5 / 0
errInLineHandler:
    If Err.Number <> 0 Then
         ' some complex code that could result in other errors
        On Error GoTo -1
    End If
    On Error GoTo 0
    
    'other code:
    l = 6 / 0
End Sub

The warning "OnErroGoto -1" that RD throws states that "the error state is also cleared in addition to disabling any error handling.

This description is wrong, as "On Error GoTo -1" only disactivate the error state, without disabling the enabled error handling ("On Error GoTo xxxxx").

Comment the line "On Error GoTo 0" in my code and you'll see that the following "l = 6 / 0" will jump to errInLineHandler instead than breaking the code as for the description meaning.

Furthermore, the description states that the On Error GoTo -1 "can be ambiguous as a negative line label of -1 may end up as a target [...]" while a negative labels cannot exist as the VBE immediately consider it a syntax error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIdentifies work items for known bugsdifficulty-01-ducklingIssue where no particularly involved knowledge of the internal API is needed.feature-inspectionsup-for-grabsUse this label in conjunction with a difficulty level label, e.g. difficulty-02-ducky

    Type

    No type

    Projects

    Status

    Prioritization

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions