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 public class FileUploadException extends Exception {
26
27 /**
28 * Serial version UID, being used, if the exception
29 * is serialized.
30 */
31 private static final long serialVersionUID = 8881893724388807504L;
32
33 /**
34 * The exceptions cause. We overwrite the cause of
35 * the super class, which isn't available in Java 1.3.
36 */
37 private final Throwable cause;
38
39 /**
40 * Constructs a new <code>FileUploadException</code> without message.
41 */
42 public FileUploadException() {
43 this(null, null);
44 }
45
46 /**
47 * Constructs a new <code>FileUploadException</code> with specified detail
48 * message.
49 *
50 * @param msg the error message.
51 */
52 public FileUploadException(final String msg) {
53 this(msg, null);
54 }
55
56 /**
57 * Creates a new <code>FileUploadException</code> with the given
58 * detail message and cause.
59 *
60 * @param msg The exceptions detail message.
61 * @param cause The exceptions cause.
62 */
63 public FileUploadException(String msg, Throwable cause) {
64 super(msg);
65 this.cause = cause;
66 }
67
68 /**
69 * Prints this throwable and its backtrace to the specified print stream.
70 *
71 * @param stream <code>PrintStream</code> to use for output
72 */
73 @Override
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 @Override
89 public void printStackTrace(PrintWriter writer) {
90 super.printStackTrace(writer);
91 if (cause != null) {
92 writer.println("Caused by:");
93 cause.printStackTrace(writer);
94 }
95 }
96
97 /**
98 * {@inheritDoc}
99 */
100 @Override
101 public Throwable getCause() {
102 return cause;
103 }
104
105 }