Interesting problem. I have never used trap (although it has been on my todo list for a while) so I can't give you a fix, but I think I can see what goes wrong.
When you call dummy the error handler is invoked, but you are not in the context of the invoking call anymore, so the variable assignment never happens.
If you add
to the end of the error handlers function body you get
x value is 1
z value is
Onviously not a fix, but it gives a pointer as to how the code behaves. I'll play a bit with this further...