Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

perl.exe has encountered an error and needs to close

by xdg (Monsignor)
on Mar 26, 2008 at 08:40 UTC ( [id://676334]=perlmeditation: print w/replies, xml ) Need Help??

Many times when running perl on Windows, I've seen a hard crash or segfault that pops up a dialog box with the dreaded text

perl.exe has encountered an error and needs to close

and everything comes to a halt until I press the button to close the dialog.

I wrote about one trigger for this in Perl 5.8 in Tainted fork crash on Win32, but it has happened in other circumstances as well when some XS module or other does something it's not supposed to.

This behavior is really annoying if I'm running some sort of batch process where I can handle sub-process failures as long as they actually finish failing and return an error value.

Fortunately, I recently found a workaround that suppresses the dialog box: KB#124873: Disabling System Hard Error Message Dialog Boxes. On WinXP, at least, it requires setting the following registry key to "2":

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Windows\ErrorMode

While that's a global change, I believe there's also a way to set this for a process and its children using the Win32 function SetErrorMode.

I haven't tried it and I don't think any current CPAN module offers an interface to this, but it wouldn't be hard to do with Win32::API.

use Win32::API; Win32::API->Import( 'kernel32' => 'int SetErrorMode(int a)' ); SetErrorMode(2)

I hope this helps some other annoyed monks out there.

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Replies are listed 'Best First'.
Re: perl.exe has encountered an error and needs to close
by syphilis (Archbishop) on Mar 26, 2008 at 09:42 UTC
    I don't think any current CPAN module offers an interface to this

    Looks like Win32API::File already wraps SetErrorMode. (That doesn't mean that drawing attention to the existence/usefulness of SetErrorMode was a waste of time ... ++ for presenting the meditation.)

    Cheers,
    Rob

      That's interesting/useful to know. I still think I might eventually get around to writing a separate Win32::ErrorMode module for clarity, but ++ for that pointer.

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

        I still think I might eventually get around to writing a separate Win32::ErrorMode module for clarity

        Certainly wouldn't hurt. It's not entirely expected that error modes would be handled by a module named Win32API::File. I actually remembered from a long time ago that the function was covered by a perl module ... couldn't remember the name of the module, so found it by searching an old perl 5.6 installation for all files that contained "SetErrorMode".

        As an aside, I have a long-abandoned module sitting on one of my much-disused Windows boxes called Win32::YAWN - Yet Another Windows Module (with mandatory and appropriate typo). It contains, among other ad-hoc Win32 API wrappings, an XSub that wraps SetErrorMode.

        You had better be quick ;-)

        Cheers,
        Rob
Re: perl.exe has encountered an error and needs to close
by BrowserUk (Patriarch) on Mar 26, 2008 at 12:14 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://676334]
Approved by Corion
Front-paged by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-03-28 08:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found