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.


In reply to perl.exe has encountered an error and needs to close by xdg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.