It was not obvious from the reading that it would work when trap is inside the function but that is exactly what I need.
Again, may be it is just me, but the reading with the back and forth reading and long distance jump in the docco to figure out how it works looks complicated, but that's good enough, I can proceed :-) Thanx tons @greg @chet