vba - On Error Goto doesn't work inside EventHandler subs -


lets assume code:

module1:

sub main()      dim cl new class2     on error goto errorhandler1         cl.dowork      on error goto 0 exit sub  errorhandler1:     msgbox (err.description)  end sub 

class1:

event myevent()  public sub dowork()     raiseevent myevent end sub 

class2:

private withevents cl class1  private sub cl_myevent()     call err.raise(123, , "errorinclass") end sub  private sub class_initialize()     set cl = new class1 end sub  public sub dowork()     cl.dowork end sub 

i expect errorhandler1 launch , msgbox err.description shown. throws me runtime error instead.

what have handle errors within eventhandlers routines?

as can read here:

if use raise method of err object raise error, can force visual basic search backward through calls list enabled error handler.

but in case there no enabled error handler.

maybe inform client of class2 work failed. here because client of class2 standard module can't use events class2, maybe simple read-only property might here?

module:

sub main()     cl.dowork     if not cl.isworkok msgbox "work failed..."     on error goto 0     exit sub  errorhandler1:     msgbox (err.description)  end sub 

class2:

private m_isworkok boolean  private sub cl_myevent()     on error goto errmyevent     call err.raise(123, , "errorinclass")     m_isworkok = true     exit sub errmyevent:     m_isworkok = false end sub  public property isworkok() boolean     isworkok = m_isworkok end property 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -