0

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:

  1. 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
    
  2. 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
    
  3. 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"

enter image description here

Why isn't the error bubbling up to Workbook_Open() where I can catch it?

Thanks, Geoff

Geoff L
  • 765
  • 5
  • 22
  • Previously: https://stackoverflow.com/questions/12687105/break-in-class-module-vs-break-on-unhandled-errors-vb6-error-trapping-options – Tim Williams Jul 28 '23 at 00:50

1 Answers1

0

The VBE for excel includes options for class module error handling. So check your options under Tools | Options. You should not enable the option to Break in Class Modules

enter image description here

topsail
  • 2,186
  • 3
  • 17
  • 17
  • Ah ok great thanks. But if I turn off Break in Class Module, and there's an unhandled error, it doesn't show you where in the class the error occurred. Is there a way to keep that part? Also, is that setting file specific? Would every user need to go into VBA to set that? – Geoff L Jul 28 '23 at 00:19
  • Not that I know of - usually for testing I enable break in class modules, and when I'm satisfied with my class code I turn the option off. – topsail Jul 28 '23 at 00:23