How can I prevent Windows from catching my Perl exceptions?

I have this Perl software that should work 24/7. It continues to open a connection to the IMAP server, checks for new mail, and then classifies the new messages.

Now I have a user who is sleeping on his XP laptop every once in a while. When this happens, the connection to the server fails and an exception is thrown. The calling code usually catches this exception and tries to reconnect. But in this case, it seems that Windows (or Perl?) Catches the exception and delivers it to the user through the message box.

Does anyone know how I can prevent this kind of wtf? Could my code receive a "system-is-about-to-hibernate" signal?

To clarify some points that you have already raised:

  • I have no problem with sleeping computers. I just need to find a way to handle this.
  • The Perl module in question throws an exception. It does something like a "die" foo bar. Although the application is completely browser-based and does not use anything like Wx or Tk, the user receives a window with the message "poll_timer". The contents of this message box are exactly the contents of $@ ('foo bar' in this example).
  • The application is compiled into an executable file using perlapp . However, the documentation says nothing about exception handling.
+4
source share
4 answers

I think you are dealing with an exception at the OS level and not with Perl. The corresponding Perl module makes a call for something in the DLL (I suppose), and gets an exception. It would be best to weld it up to a simple replicated test that throws an exception (you may need a lot of hibernation and waking up the machines involved in this process). Then send this information to the module developer and ask them if they can come up with a way to catch this exception in a way that is more useful to you.

If the module developer cannot or does not help, you probably want to use the Perl debugger to debug the module code and see what happens, and see if there is a way you can change the module yourself to catch and handle the exception.

+1
source

Your user is no exception, but rather a rule. My laptop is sleeping between work and home. At work, he is connected to a DHCP network; at home, it’s completely different. Most programs continue to work, despite the confusing set of IP addresses (VMWare, VPN, normal old connection through a NAT router). Those who do not do this (AT & T Net Client, for VPNs that are not used in the office, necessary at home or on the road) recognize the disconnection to sleep mode (AT & T Net Client supports the StandBy / Hibernate process until it disconnects), and I reconnect if necessary when the car wakes up. At airports, I use local Wi-Fi (more DHCP), but completely disconnected (one physical switch) before boarding the plane.

So, you need to learn how to find out that the machine goes into StandBy or Hibernation mode so that your software can be used. What I do not have, I'm sorry that this is a recipe for what you need to do.

Some work with Google suggests that ACPI (Advanced Configuration and Power Interface) is part of the solution ( Microsoft ). APM (Advanced Power Management) may also be relevant.

0
source

It is difficult to offer intelligent sentences without seeing the corresponding bits of code. If you get a dialog box with an exception message, the program most likely uses either the Tk or wxPerl GUI library, which can complicate things a bit. With that said, I assume that it would be quite easy to modify the exception handling in the program by wrapping the point of failure in the eval block and testing $@ after the call. If $@ contains an error message indicating a connection failure, then reconnect and continue.

0
source

I found a hack to avoid modal system dialog boxes for hard errors (for example, "met and excluded and had to close"). I don't know if the same trick will work for the kind of error you are describing, but you can try.

See: Avoid the dialog "encountered a problem and must be closed" in Windows

In short, set the HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Windows \ ErrorMode registry key to the value "2".

0
source

All Articles