A short answer to your first question: "you should not put an error handler in every procedure."
To say that “every procedure must have an error handler” is, in general, terrible advice. The disadvantages of handling VBA errors have been discussed elsewhere. Conceptually, however, this is not all that differs from the more standard form of exception handling found in other languages. Most of the best practices in these languages ​​apply. You should handle errors at the lowest level, where handling them makes sense. Sometimes this happens in the procedure where the error occurred, many times not.
For example, a VBA UDF called from your worksheet must necessarily have an EH that ensures that you return the Excel error value to the calling cell (s) instead of dropping the user into the code editor with the error message. However, the code you call from this UDF may not be needed. In fact, often the most significant thing an internal routine can do when an error occurs is simply to let it go through the stack so that it can reach code that knows what to do with it. It really depends on the routine.
The answer to your second question is that the author does not seem to be very good at handling exceptions. He admits that error handling is context-specific, but then it seems that each procedure should locally decide between "fix the problem right here and resume execution" and "end the program." He usually leaves the correct option, which is "cleared locally and raises the problem above." Thus, routines that do not need to be cleaned locally should simply make bubbles.
jtolle Sep 13 '09 at 23:51 2009-09-13 23:51
source share