1/* 2 * Copyright (c) 2000, 2016, 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 26package java.awt; 27 28/** 29 * Thrown when code that is dependent on a keyboard, display, or mouse 30 * is called in an environment that does not support a keyboard, display, 31 * or mouse. Any code that depends on any of those devices should firstly 32 * ensure their availability using the {@code GraphicsEnvironment.isHeadless()} 33 * method and throw {@code HeadlessException} if the latter returns 34 * {@code true}. 35 * 36 * @since 1.4 37 * @author Michael Martak 38 * @see GraphicsEnvironment#isHeadless 39 */ 40public class HeadlessException extends UnsupportedOperationException { 41 /* 42 * JDK 1.4 serialVersionUID 43 */ 44 private static final long serialVersionUID = 167183644944358563L; 45 46 /** 47 * Constructs new {@code HeadlessException} with empty message. 48 * For such {@code HeadlessException} the default headless error message 49 * may be auto-generated for some platforms. 50 * The text of the default headless message may depend on 51 * whether the GraphicsEnvironment is in fact headless. 52 * That is, the default headless message is both system and environmentally 53 * dependent. 54 */ 55 public HeadlessException() {} 56 57 /** 58 * Create a new instance with the specified detailed error message. 59 * For some platforms the default headless error message may be 60 * added at the end of the specified message. 61 * The text of the default headless message may depend on 62 * whether the GraphicsEnvironment is in fact headless. 63 * That is, the default headless message is both system and environmentally 64 * dependent. 65 * 66 * @param msg the error message 67 */ 68 public HeadlessException(String msg) { 69 super(msg); 70 } 71 72 /** 73 * Returns the detail message string of this {@code HeadlessException}. 74 * Depending on the platform the message specified in the constructor may 75 * be followed by the default headless error message. 76 * The text of the default headless message may depend on 77 * whether the GraphicsEnvironment is in fact headless. 78 * That is, the default headless message is both system and environmentally 79 * dependent. 80 * 81 * @return the detail message string of this {@code HeadlessException} 82 * instance (which may be {@code null}). 83 */ 84 public String getMessage() { 85 String superMessage = super.getMessage(); 86 String headlessMessage = GraphicsEnvironment.getHeadlessMessage(); 87 88 if (superMessage == null) { 89 return headlessMessage; 90 } else if (headlessMessage == null) { 91 return superMessage; 92 } else { 93 return superMessage + headlessMessage; 94 } 95 } 96} 97