Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxws/src/share/jaxws_classes/javax/xml/soap/SOAPException.java
38890 views
/*1* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.xml.soap;2627/**28* An exception that signals that a SOAP exception has occurred. A29* <code>SOAPException</code> object may contain a <code>String</code>30* that gives the reason for the exception, an embedded31* <code>Throwable</code> object, or both. This class provides methods32* for retrieving reason messages and for retrieving the embedded33* <code>Throwable</code> object.34*35* <P> Typical reasons for throwing a <code>SOAPException</code>36* object are problems such as difficulty setting a header, not being37* able to send a message, and not being able to get a connection with38* the provider. Reasons for embedding a <code>Throwable</code>39* object include problems such as input/output errors or a parsing40* problem, such as an error in parsing a header.41*/42public class SOAPException extends Exception {43private Throwable cause;4445/**46* Constructs a <code>SOAPException</code> object with no47* reason or embedded <code>Throwable</code> object.48*/49public SOAPException() {50super();51this.cause = null;52}5354/**55* Constructs a <code>SOAPException</code> object with the given56* <code>String</code> as the reason for the exception being thrown.57*58* @param reason a description of what caused the exception59*/60public SOAPException(String reason) {61super(reason);62this.cause = null;63}6465/**66* Constructs a <code>SOAPException</code> object with the given67* <code>String</code> as the reason for the exception being thrown68* and the given <code>Throwable</code> object as an embedded69* exception.70*71* @param reason a description of what caused the exception72* @param cause a <code>Throwable</code> object that is to73* be embedded in this <code>SOAPException</code> object74*/75public SOAPException(String reason, Throwable cause) {76super(reason);77initCause(cause);78}7980/**81* Constructs a <code>SOAPException</code> object initialized82* with the given <code>Throwable</code> object.83*/84public SOAPException(Throwable cause) {85super(cause.toString());86initCause(cause);87}8889/**90* Returns the detail message for this <code>SOAPException</code>91* object.92* <P>93* If there is an embedded <code>Throwable</code> object, and if the94* <code>SOAPException</code> object has no detail message of its95* own, this method will return the detail message from the embedded96* <code>Throwable</code> object.97*98* @return the error or warning message for this99* <code>SOAPException</code> or, if it has none, the100* message of the embedded <code>Throwable</code> object,101* if there is one102*/103public String getMessage() {104String message = super.getMessage();105if (message == null && cause != null) {106return cause.getMessage();107} else {108return message;109}110}111112/**113* Returns the <code>Throwable</code> object embedded in this114* <code>SOAPException</code> if there is one. Otherwise, this method115* returns <code>null</code>.116*117* @return the embedded <code>Throwable</code> object or <code>null</code>118* if there is none119*/120121public Throwable getCause() {122return cause;123}124125/**126* Initializes the <code>cause</code> field of this <code>SOAPException</code>127* object with the given <code>Throwable</code> object.128* <P>129* This method can be called at most once. It is generally called from130* within the constructor or immediately after the constructor has131* returned a new <code>SOAPException</code> object.132* If this <code>SOAPException</code> object was created with the133* constructor {@link #SOAPException(Throwable)} or134* {@link #SOAPException(String,Throwable)}, meaning that its135* <code>cause</code> field already has a value, this method cannot be136* called even once.137*138* @param cause the <code>Throwable</code> object that caused this139* <code>SOAPException</code> object to be thrown. The value of this140* parameter is saved for later retrieval by the141* {@link #getCause()} method. A <tt>null</tt> value is142* permitted and indicates that the cause is nonexistent or143* unknown.144* @return a reference to this <code>SOAPException</code> instance145* @throws IllegalArgumentException if <code>cause</code> is this146* <code>Throwable</code> object. (A <code>Throwable</code> object147* cannot be its own cause.)148* @throws IllegalStateException if the cause for this <code>SOAPException</code> object149* has already been initialized150*/151public synchronized Throwable initCause(Throwable cause) {152if (this.cause != null) {153throw new IllegalStateException("Can't override cause");154}155if (cause == this) {156throw new IllegalArgumentException("Self-causation not permitted");157}158this.cause = cause;159160return this;161}162}163164165