Path: blob/master/src/java.security.sasl/share/classes/javax/security/sasl/SaslException.java
41159 views
/*1* Copyright (c) 1999, 2013, 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.security.sasl;2627import java.io.IOException;2829/**30* This class represents an error that has occurred when using SASL.31*32* @since 1.533*34* @author Rosanna Lee35* @author Rob Weltman36*/3738public class SaslException extends IOException {39/**40* The possibly null root cause exception.41* @serial42*/43// Required for serialization interoperability with JSR 2844private Throwable _exception;4546/**47* Constructs a new instance of {@code SaslException}.48* The root exception and the detailed message are null.49*/50public SaslException () {51super();52}5354/**55* Constructs a new instance of {@code SaslException} with a detailed message.56* The root exception is null.57* @param detail A possibly null string containing details of the exception.58*59* @see java.lang.Throwable#getMessage60*/61public SaslException (String detail) {62super(detail);63}6465/**66* Constructs a new instance of {@code SaslException} with a detailed message67* and a root exception.68* For example, a SaslException might result from a problem with69* the callback handler, which might throw a NoSuchCallbackException if70* it does not support the requested callback, or throw an IOException71* if it had problems obtaining data for the callback. The72* SaslException's root exception would be then be the exception thrown73* by the callback handler.74*75* @param detail A possibly null string containing details of the exception.76* @param ex A possibly null root exception that caused this exception.77*78* @see java.lang.Throwable#getMessage79* @see #getCause80*/81public SaslException (String detail, Throwable ex) {82super(detail);83if (ex != null) {84initCause(ex);85}86}8788/*89* Override Throwable.getCause() to ensure deserialized object from90* JSR 28 would return same value for getCause() (i.e., _exception).91*/92public Throwable getCause() {93return _exception;94}9596/*97* Override Throwable.initCause() to match getCause() by updating98* _exception as well.99*/100public Throwable initCause(Throwable cause) {101super.initCause(cause);102_exception = cause;103return this;104}105106/**107* Returns the string representation of this exception.108* The string representation contains109* this exception's class name, its detailed message, and if110* it has a root exception, the string representation of the root111* exception. This string representation112* is meant for debugging and not meant to be interpreted113* programmatically.114* @return The non-null string representation of this exception.115* @see java.lang.Throwable#getMessage116*/117// Override Throwable.toString() to conform to JSR 28118public String toString() {119String answer = super.toString();120if (_exception != null && _exception != this) {121answer += " [Caused by " + _exception.toString() + "]";122}123return answer;124}125126/** Use serialVersionUID from JSR 28 RI for interoperability */127private static final long serialVersionUID = 4579784287983423626L;128}129130131