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   * Exception for errors encountered while processing the request.
24   *
25   * @version $Id: FileUploadException.java 1454690 2013-03-09 12:08:48Z simonetripodi $
26   */
27  public class FileUploadException extends Exception {
28  
29      /**
30       * Serial version UID, being used, if the exception
31       * is serialized.
32       */
33      private static final long serialVersionUID = 8881893724388807504L;
34  
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       *
62       * @param msg The exceptions detail message.
63       * @param cause The exceptions cause.
64       */
65      public FileUploadException(String msg, Throwable cause) {
66          super(msg);
67          this.cause = cause;
68      }
69  
70      /**
71       * Prints this throwable and its backtrace to the specified print stream.
72       *
73       * @param stream <code>PrintStream</code> to use for output
74       */
75      @Override
76      public void printStackTrace(PrintStream stream) {
77          super.printStackTrace(stream);
78          if (cause != null) {
79              stream.println("Caused by:");
80              cause.printStackTrace(stream);
81          }
82      }
83  
84      /**
85       * Prints this throwable and its backtrace to the specified
86       * print writer.
87       *
88       * @param writer <code>PrintWriter</code> to use for output
89       */
90      @Override
91      public void printStackTrace(PrintWriter writer) {
92          super.printStackTrace(writer);
93          if (cause != null) {
94              writer.println("Caused by:");
95              cause.printStackTrace(writer);
96          }
97      }
98  
99      /**
100      * {@inheritDoc}
101      */
102     @Override
103     public Throwable getCause() {
104         return cause;
105     }
106 
107 }