View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  package org.apache.commons.fileupload;
    18
    19  import java.io.PrintStream;
    20  import java.io.PrintWriter;
    21
    22
    23  /**
    24   * Exception for errors encountered while processing the request.
    25   *
    26   * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
    27   * @version $Id: FileUploadException.java 551000 2007-06-27 00:59:16Z jochen $
    28   */
    29  public class FileUploadException extends Exception {
    30      /**
    31       * Serial version UID, being used, if the exception
    32       * is serialized.
    33       */
    34      private static final long serialVersionUID = 8881893724388807504L;
    35      /**
    36       * The exceptions cause. We overwrite the cause of
    37       * the super class, which isn't available in Java 1.3.
    38       */
    39      private final Throwable cause;
    40
    41      /**
    42       * Constructs a new <code>FileUploadException</code> without message.
    43       */
    44      public FileUploadException() {
    45          this(null, null);
    46      }
    47
    48      /**
    49       * Constructs a new <code>FileUploadException</code> with specified detail
    50       * message.
    51       *
    52       * @param msg the error message.
    53       */
    54      public FileUploadException(final String msg) {
    55          this(msg, null);
    56      }
    57
    58      /**
    59       * Creates a new <code>FileUploadException</code> with the given
    60       * detail message and cause.
    61       * @param msg The exceptions detail message.
    62       * @param cause The exceptions cause.
    63       */
    64      public FileUploadException(String msg, Throwable cause) {
    65          super(msg);
    66          this.cause = cause;
    67      }
    68
    69      /**
    70       * Prints this throwable and its backtrace to the specified print stream.
    71       *
    72       * @param stream <code>PrintStream</code> to use for output
    73       */
    74      public void printStackTrace(PrintStream stream) {
    75          super.printStackTrace(stream);
    76          if (cause != null) {
    77              stream.println("Caused by:");
    78              cause.printStackTrace(stream);
    79          }
    80      }
    81
    82      /**
    83       * Prints this throwable and its backtrace to the specified
    84       * print writer.
    85       *
    86       * @param writer <code>PrintWriter</code> to use for output
    87       */
    88      public void printStackTrace(PrintWriter writer) {
    89          super.printStackTrace(writer);
    90          if (cause != null) {
    91              writer.println("Caused by:");
    92              cause.printStackTrace(writer);
    93          }
    94      }
    95
    96      public Throwable getCause() {
    97          return cause;
    98      }
    99  }