When there's an error I would like to do some cleanup and then let the error flow up so that it's handled globally.
In C# I would do a try finally
but that is not possible with VBA, only On Eror GoTo <mylabel>
.
How can I rethrow the error properly when caught in the label?
Is it only possible calling Err.Raise again with all properties, no throw
like keyword exists?:
Err.Raise Err.Number, Err.Source, Err.Description, Err.HelpFile, Err.HelpContext
That is the correct method, but no, you don't have to re-state all the err properties. The values are retained:
err.raise Err.Number
is the same as
Err.Raise Err.Number, Err.Source, Err.Description, Err.HelpFile, Err.HelpContext
https://docs.microsoft.com/en-us/office/vba/Language/Reference/user-interface-help/raise-method
It can be more complex if you are throwing out of a class module. By default, the err object of a class module is caught and re-created, so depending on how it is declared, properties may be replaced.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With