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 * 025 * @version $Id: FileUploadException.java 1454690 2013-03-09 12:08:48Z simonetripodi $ 026 */ 027public class FileUploadException extends Exception { 028 029 /** 030 * Serial version UID, being used, if the exception 031 * is serialized. 032 */ 033 private static final long serialVersionUID = 8881893724388807504L; 034 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 * 062 * @param msg The exceptions detail message. 063 * @param cause The exceptions cause. 064 */ 065 public FileUploadException(String msg, Throwable cause) { 066 super(msg); 067 this.cause = cause; 068 } 069 070 /** 071 * Prints this throwable and its backtrace to the specified print stream. 072 * 073 * @param stream <code>PrintStream</code> to use for output 074 */ 075 @Override 076 public void printStackTrace(PrintStream stream) { 077 super.printStackTrace(stream); 078 if (cause != null) { 079 stream.println("Caused by:"); 080 cause.printStackTrace(stream); 081 } 082 } 083 084 /** 085 * Prints this throwable and its backtrace to the specified 086 * print writer. 087 * 088 * @param writer <code>PrintWriter</code> to use for output 089 */ 090 @Override 091 public void printStackTrace(PrintWriter writer) { 092 super.printStackTrace(writer); 093 if (cause != null) { 094 writer.println("Caused by:"); 095 cause.printStackTrace(writer); 096 } 097 } 098 099 /** 100 * {@inheritDoc} 101 */ 102 @Override 103 public Throwable getCause() { 104 return cause; 105 } 106 107}