Error handling with nested subroutines

davemcwish

New Member
Joined
Nov 12, 2013
Messages
11
I have a Sub procedure that calls, in sequence, 5 other sub procedures:-

Code:
Sub Analyse


On Error GoTo ErrHandler:


Call Sub_A
Call Sub_B (output from Sub_A)
Call Sub_C (output from Sub_B)
Call Sub_D (output from Sub_C)
Call Sub_E (output from Sub_D)


ErrHandler:


End


If Err.Number <> 0 Then
strEmailErrorText = "Runtime Error" & vbCrLf & vbCrLf & "Module: " & Application.VBE.ActiveCodePane.CodeModule.Name & vbCrLf & "Procedure: " & strProcedureName & vbCrLf & "Line: " & Erl & vbCrLf & vbCrLf & DisplayADSIError()
Call MsgBox(strEmailErrorText, vbCritical + vbSystemModal, strToolName)
 Call Email_Support(strEmailErrorText)
'120   End If


End Sub


I currently have error handling within each of
Sub_A
Sub_B
Sub_C
Sub_D
Sub_E

identical to that shown above.

Given the dependencies, if there is an error in any of A through E I'd like error handling to manage the error as is found and then terminate (Sub Analyse) completely. Currently if I get an error in e.g. Sub_B, the local error handling deals with it and then the code continues with Sub_C.

Thoughts ?
 
Last edited:

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I found a way to achieve this that involved setting a public variable of boolean datatype within the ErrHandler sections and a whole load of nested if's that only ran if the variable = false. It works, but I'm not sure that's the best way of doing it.
 
Upvote 0

Forum statistics

Threads
1,214,521
Messages
6,120,018
Members
448,937
Latest member
BeerMan23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top