gri6507 has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,

I have a Tk program that catches the Xwin "close window" event: $mw->protocol('WM_DELETE_WINDOW', sub {my_exit()});. However, when sometime down the road in the program a bad thing happens and I call die "bad thing happened: $!\n";, the program terminates, the windown obviously is removed, but my_exit() function is not executed. I had to put in a signal catcher $SIG{__DIE__}=sub{my_exit()}; in order to do what I wanted.

Why is that? Why doesn't the 'die' force the WM_DELETE_WINDOW event to be caught?

Replies are listed 'Best First'.
Re: Tk & Xwin event order
by chromatic (Archbishop) on May 25, 2004 at 23:18 UTC
    Why doesn't the 'die' force the WM_DELETE_WINDOW event to be caught?

    As far as I know, that's because die is not a window manager event. It's completely outside of Tk's event loop.

    You could put an END block in your main code that calls my_exit(). If you do that, you'll need to make sure that it's safe to call that twice or set a flag that you've already called it.