|
-
Jan 25th, 2025, 06:47 AM
#6
Re: Classic VB - What is wrong with using "On Error Resume Next"?
> Why does CodeSmart recommend "You should always use 'On Error Resume Next' error handling in 'Terminate' events."?
The correct reason is that "destructors should not raise exceptions".
Using OERN is the worst thing you can do in Terminate event or even more generally using On Error statement per se in Terminate event is a disastrous approach.
The reason for this is that destructors (Terminate event) are always called when an instance goes out of scope incl. when this object deallocation happens during error handling in an unrelated procedure.
When error propagates and a Terminate event with On Error statement is called during propagation then the Err object get cleared by the On Error statement so the original error is lost *before* propagation reaching an error handler. Ouch!
Using OERN in Terminate event does not solve the problem, you just have to leave Terminate event *without* error handler and ensure every procedures the code calls has no On Error statement. That is try to prevent errors being raised at all costs without using On Error statement i.e. cannot just call VB.Collection's Item method to test if a key exsists with OERN in any code called from Terminate event.
This is one of the reason why I run VB IDE with Break on All Errors setting set and do not depend on OERN for any logical application code construction i.e. don't implement program logic using error handling/exceptions.
cheers,
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|