View Javadoc

    1
    2
    3   /*
    4    * The contents of this file are subject to the terms
    5    * of the Common Development and Distribution License
    6    * (the "License").  You may not use this file except
    7    * in compliance with the License.
    8    *
    9    * You can obtain a copy of the license at
    10   * glassfish/bootstrap/legal/CDDLv1.0.txt or
    11   * https://glassfish.dev.java.net/public/CDDLv1.0.html.
    12   * See the License for the specific language governing
    13   * permissions and limitations under the License.
    14   *
    15   * When distributing Covered Code, include this CDDL
    16   * HEADER in each file and include the License file at
    17   * glassfish/bootstrap/legal/CDDLv1.0.txt.  If applicable,
    18   * add the following below this CDDL HEADER, with the
    19   * fields enclosed by brackets "[]" replaced with your
    20   * own identifying information: Portions Copyright [yyyy]
    21   * [name of copyright owner]
    22   *
    23   * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
    24   *
    25   * Portions Copyright Apache Software Foundation.
    26   */
    27
    28  package javax.servlet;
    29
    30
    31  /**
    32   * Defines a general exception a servlet can throw when it
    33   * encounters difficulty.
    34   *
    35   * @author 	Various
    36   */
    37
    38
    39  public class ServletException extends Exception {
    40
    41      private Throwable rootCause;
    42
    43
    44
    45
    46
    47      /**
    48       * Constructs a new servlet exception.
    49       *
    50       */
    51
    52      public ServletException() {
    53  	super();
    54      }
    55
    56
    57
    58
    59
    60      /**
    61       * Constructs a new servlet exception with the
    62       * specified message. The message can be written
    63       * to the server log and/or displayed for the user.
    64       *
    65       * @param message 		a <code>String</code>
    66       *				specifying the text of
    67       *				the exception message
    68       *
    69       */
    70
    71      public ServletException(String message) {
    72  	super(message);
    73      }
    74
    75
    76
    77
    78
    79      /**
    80       * Constructs a new servlet exception when the servlet
    81       * needs to throw an exception and include a message
    82       * about the "root cause" exception that interfered with its
    83       * normal operation, including a description message.
    84       *
    85       *
    86       * @param message 		a <code>String</code> containing
    87       *				the text of the exception message
    88       *
    89       * @param rootCause		the <code>Throwable</code> exception
    90       *				that interfered with the servlet's
    91       *				normal operation, making this servlet
    92       *				exception necessary
    93       *
    94       */
    95
    96      public ServletException(String message, Throwable rootCause) {
    97  	super(message, rootCause);
    98  	this.rootCause = rootCause;
    99      }
    100
    101
    102
    103
    104
    105     /**
    106      * Constructs a new servlet exception when the servlet
    107      * needs to throw an exception and include a message
    108      * about the "root cause" exception that interfered with its
    109      * normal operation.  The exception's message is based on the localized
    110      * message of the underlying exception.
    111      *
    112      * <p>This method calls the <code>getLocalizedMessage</code> method
    113      * on the <code>Throwable</code> exception to get a localized exception
    114      * message. When subclassing <code>ServletException</code>,
    115      * this method can be overridden to create an exception message
    116      * designed for a specific locale.
    117      *
    118      * @param rootCause 	the <code>Throwable</code> exception
    119      * 				that interfered with the servlet's
    120      *				normal operation, making the servlet exception
    121      *				necessary
    122      *
    123      */
    124
    125     public ServletException(Throwable rootCause) {
    126 	super(rootCause);
    127 	this.rootCause = rootCause;
    128     }
    129
    130
    131
    132
    133
    134     /**
    135      * Returns the exception that caused this servlet exception.
    136      *
    137      *
    138      * @return			the <code>Throwable</code>
    139      *				that caused this servlet exception
    140      *
    141      */
    142
    143     public Throwable getRootCause() {
    144 	return rootCause;
    145     }
    146 }
    147
    148
    149
    150
    151