- Local time
- Today, 06:30
- Joined
- Feb 28, 2001
- Messages
- 30,495
I use a slightly different approach. My code usually does something like this:
The reason I do it this way is that when I have special cleanup, I don't want that done in the context of a trap handler because a trap cannot interrupt a trap. If my special cleanup can itself incur an error, I get into a really awkward situation, a "trap loop." REALLY a pain to fix. If I use tested and debugged methods of event logging and message notification, then resume in the normal code body but in an error pathway, I can immediately cancel or replace the error handler (to stop potential trap loops on cleanup).
We must remember that at least in theory, traps are queued to your process asynchronously and Access has to linearize them because a trap cannot interrupt a trap. So we have to be careful about allowing a trap to cause a condition that would signal a trap.
The reason is that the same handler that triggered the trap is STILL the declared trap handler in that context. Taking a trap is NOT a one-shot deal. The declared trap handler is part of the call frame still in effect for that subroutine.
So where does the trap go? Right back to the place that caused it (for the bad handler case). Don't worry, it will eventually stop when all the memory leaks eventually eat all of the heap space. Give it a couple of days. Of course, if you have a multi-core machine, you will be able to get enough CPU time to activate and employ task manager to kill that wild process, which might saturate one core of your CPU if you weren't doing any message boxes as part of the process.
Code:
ON ERROR GOTO WHOOPSIE
{main code}
GOTO FINISHSUB
WHOOPSIE:
{event logging, message boxes, not much else}
RESUME FINISHSUBERR
FINISHSUBERR:
ON ERROR RESUME NEXT
{special cleanup}
'fall through to ...
FINISHSUB:
{normal cleanup}
END SUB
The reason I do it this way is that when I have special cleanup, I don't want that done in the context of a trap handler because a trap cannot interrupt a trap. If my special cleanup can itself incur an error, I get into a really awkward situation, a "trap loop." REALLY a pain to fix. If I use tested and debugged methods of event logging and message notification, then resume in the normal code body but in an error pathway, I can immediately cancel or replace the error handler (to stop potential trap loops on cleanup).
We must remember that at least in theory, traps are queued to your process asynchronously and Access has to linearize them because a trap cannot interrupt a trap. So we have to be careful about allowing a trap to cause a condition that would signal a trap.
The reason is that the same handler that triggered the trap is STILL the declared trap handler in that context. Taking a trap is NOT a one-shot deal. The declared trap handler is part of the call frame still in effect for that subroutine.
So where does the trap go? Right back to the place that caused it (for the bad handler case). Don't worry, it will eventually stop when all the memory leaks eventually eat all of the heap space. Give it a couple of days. Of course, if you have a multi-core machine, you will be able to get enough CPU time to activate and employ task manager to kill that wild process, which might saturate one core of your CPU if you weren't doing any message boxes as part of the process.
Last edited: