When an error occurs inside a function without an On Error statement, I thought it's supposed to bubble up to the first calling parent function with an On Error statement, but for some reason its not working and I have no idea why.
The following code is a minimum reproducible example. It doesn't do anything except demonstrate the error. There are 3 files in the program:
In Workbook_Open() function inside ThisWorkbook file, I have the following code:
Public Sub Workbook_Open() On Error GoTo wtf Stop Dim f As New Factory Call f.createM_DateWithObject(Now) MsgBox "A" Exit Sub wtf: MsgBox "B" End Sub
Then I have the first class called Factory, which contains only:
Public Sub createM_DateWithObject(ByVal dateObj As Date) 'intentional error Dim x As Integer x = "asd" End Sub
Then I have my second M_Date class:
Option Explicit Option Base 0 'ini the object using a date Public Sub iniWithObject(ByVal dateObj As Date) 'does nothing End Sub
The only On Error statement is inside Workbook_Open(), however when I run the code it stops at x = "asd"
Why isn't the error bubbling up to Workbook_Open() where I can catch it?
Thanks, Geoff