001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.commons.fileupload;
018    
019    import java.io.PrintStream;
020    import java.io.PrintWriter;
021    
022    
023    /**
024     * Exception for errors encountered while processing the request.
025     *
026     * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
027     * @version $Id: FileUploadException.java 551000 2007-06-27 00:59:16Z jochen $
028     */
029    public class FileUploadException extends Exception {
030        /**
031         * Serial version UID, being used, if the exception
032         * is serialized.
033         */
034        private static final long serialVersionUID = 8881893724388807504L;
035        /**
036         * The exceptions cause. We overwrite the cause of
037         * the super class, which isn't available in Java 1.3.
038         */
039        private final Throwable cause;
040    
041        /**
042         * Constructs a new <code>FileUploadException</code> without message.
043         */
044        public FileUploadException() {
045            this(null, null);
046        }
047    
048        /**
049         * Constructs a new <code>FileUploadException</code> with specified detail
050         * message.
051         *
052         * @param msg the error message.
053         */
054        public FileUploadException(final String msg) {
055            this(msg, null);
056        }
057    
058        /**
059         * Creates a new <code>FileUploadException</code> with the given
060         * detail message and cause.
061         * @param msg The exceptions detail message.
062         * @param cause The exceptions cause.
063         */
064        public FileUploadException(String msg, Throwable cause) {
065            super(msg);
066            this.cause = cause;
067        }
068    
069        /**
070         * Prints this throwable and its backtrace to the specified print stream.
071         *
072         * @param stream <code>PrintStream</code> to use for output
073         */
074        public void printStackTrace(PrintStream stream) {
075            super.printStackTrace(stream);
076            if (cause != null) {
077                stream.println("Caused by:");
078                cause.printStackTrace(stream);
079            }
080        }
081    
082        /**
083         * Prints this throwable and its backtrace to the specified
084         * print writer.
085         *
086         * @param writer <code>PrintWriter</code> to use for output
087         */
088        public void printStackTrace(PrintWriter writer) {
089            super.printStackTrace(writer);
090            if (cause != null) {
091                writer.println("Caused by:");
092                cause.printStackTrace(writer);
093            }
094        }
095    
096        public Throwable getCause() {
097            return cause;
098        }
099    }