tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,924
- Office Version
- 365
- 2019
- Platform
- Windows
I think neither methods below is ideal but of the two, which would be preferable?
I prefer the second but I can't accept this line, even though it works:
Code:
Option Explicit
Sub FirstMethod()
On Error GoTo FirstErrhandler
' Do something first
On Error GoTo 0
On Error GoTo SecondErrhandler
' Do something second
On Error GoTo 0
Dim a
a = 2 ' Change the value of a to another number
If a = 1 Then
' Do something third
Else
GoTo FirstErrhandler
SecondErrhandler:
MsgBox Prompt:="Another message"
Resume ResumeSecondErrhandler
FirstErrhandler:
MsgBox Prompt:="Some message"
ResumeSecondErrhandler:
' Do something fourth
End If
On Error GoTo 0
End Sub
Sub SecondMethod()
On Error GoTo FirstErrhandler
' Do something first
On Error GoTo 0
On Error GoTo SecondErrhandler
' Do something second
On Error GoTo 0
Dim a
a = 1 ' Change the value of a to another number
If a = 1 Then
' Do something third
Else
FirstErrhandler:
MsgBox Prompt:="Some message"
ResumeSecondErrhandler:
' Do something fourth
End If
On Error GoTo 0
GoTo Exitpoint ' SHOULD BE Resume Exitpoint if there was an error but GoTo Exitpoint if there isn't
SecondErrhandler:
MsgBox Prompt:="Another message"
Resume ResumeSecondErrhandler
Exitpoint:
End Sub
I prefer the second but I can't accept this line, even though it works:
Code:
GoTo Exitpoint ' SHOULD BE Resume Exitpoint if there was an error but GoTo Exitpoint if there isn't, so how can I do both?
Last edited: