1 /*
   2  * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.io;
  27 
  28 /**
  29  * Used to set the Windows error mode at VM initialization time.
  30  * <p>
  31  * The error mode decides whether the system will handle specific types of serious errors
  32  * or whether the process will handle them.
  33  *
  34  * @since 1.6
  35  */
  36 public class Win32ErrorMode {
  37 
  38     // The system does not display the critical-error-handler message box. Instead,
  39     // the system sends the error to the calling process.
  40     private static final long SEM_FAILCRITICALERRORS     = 0x0001;
  41 
  42     // The system does not display the general-protection-fault message box. This flag should
  43     // only be set by debugging applications that handle general protection (GP) faults themselves
  44     // with an exception handler.
  45     private static final long SEM_NOGPFAULTERRORBOX      = 0x0002;
  46 
  47     // The system automatically fixes memory alignment faults and makes them invisible
  48     // to the application. It does this for the calling process and any descendant processes.
  49     private static final long SEM_NOALIGNMENTFAULTEXCEPT = 0x0004;
  50 
  51     // The system does not display a message box when it fails to find a file. Instead,
  52     // the error is returned to the calling process.
  53     private static final long SEM_NOOPENFILEERRORBOX     = 0x8000;
  54 
  55     private Win32ErrorMode() {
  56     }
  57 
  58     /**
  59      * Invoke at VM initialization time to disable the critical error message box.
  60      * <p>
  61      * The critial error message box is disabled unless the system property
  62      * <tt>sun.io.allowCriticalErrorMessageBox</tt> is set to something other than
  63      * <code>false</code>. This includes the empty string.
  64      * <p>
  65      * This method does nothing if invoked after VM and class library initialization
  66      * has completed.
  67      */
  68     public static void initialize() {
  69         if (!sun.misc.VM.isBooted()) {
  70             String s = (String) System.getProperty("sun.io.allowCriticalErrorMessageBox");
  71             if (s == null || s.equals(Boolean.FALSE.toString())) {
  72                 long mode = setErrorMode(0);
  73                 mode |= SEM_FAILCRITICALERRORS;
  74                 setErrorMode(mode);
  75             }
  76         }
  77     }
  78 
  79     // Win32 SetErrorMode
  80     private static native long setErrorMode(long mode);
  81 }