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 */ 017package org.apache.commons.fileupload; 018 019import java.io.PrintStream; 020import java.io.PrintWriter; 021 022/** 023 * Exception for errors encountered while processing the request. 024 */ 025public class FileUploadException extends Exception { 026 027 /** 028 * Serial version UID, being used, if the exception 029 * is serialized. 030 */ 031 private static final long serialVersionUID = 8881893724388807504L; 032 033 /** 034 * The exceptions cause. We overwrite the cause of 035 * the super class, which isn't available in Java 1.3. 036 */ 037 private final Throwable cause; 038 039 /** 040 * Constructs a new <code>FileUploadException</code> without message. 041 */ 042 public FileUploadException() { 043 this(null, null); 044 } 045 046 /** 047 * Constructs a new <code>FileUploadException</code> with specified detail 048 * message. 049 * 050 * @param msg the error message. 051 */ 052 public FileUploadException(final String msg) { 053 this(msg, null); 054 } 055 056 /** 057 * Creates a new <code>FileUploadException</code> with the given 058 * detail message and cause. 059 * 060 * @param msg The exceptions detail message. 061 * @param cause The exceptions cause. 062 */ 063 public FileUploadException(String msg, Throwable cause) { 064 super(msg); 065 this.cause = cause; 066 } 067 068 /** 069 * Prints this throwable and its backtrace to the specified print stream. 070 * 071 * @param stream <code>PrintStream</code> to use for output 072 */ 073 @Override 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 @Override 089 public void printStackTrace(PrintWriter writer) { 090 super.printStackTrace(writer); 091 if (cause != null) { 092 writer.println("Caused by:"); 093 cause.printStackTrace(writer); 094 } 095 } 096 097 /** 098 * {@inheritDoc} 099 */ 100 @Override 101 public Throwable getCause() { 102 return cause; 103 } 104 105}