1 // 2 // $Id: JUploadException.java 95 2007-05-02 03:27:05Z 3 // /C=DE/ST=Baden-Wuerttemberg/O=ISDN4Linux/OU=Fritz 4 // Elfert/CN=svn-felfert@isdn4linux.de/emailAddress=fritz@fritz-elfert.de $ 5 // 6 // jupload - A file upload applet. 7 // Copyright 2007 The JUpload Team 8 // 9 // Created: 2006-05-09 10 // Creator: etienne_sf 11 // Last modified: $Date: 2009-11-06 22:07:21 +0100 (ven., 06 nov. 2009) $ 12 // 13 // This program is free software; you can redistribute it and/or modify it under 14 // the terms of the GNU General Public License as published by the Free Software 15 // Foundation; either version 2 of the License, or (at your option) any later 16 // version. This program is distributed in the hope that it will be useful, but 17 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 19 // details. You should have received a copy of the GNU General Public License 20 // along with this program; if not, write to the Free Software Foundation, Inc., 21 // 675 Mass Ave, Cambridge, MA 02139, USA. 22 23 package wjhk.jupload2.exception; 24 25 /** 26 * A new kind of exceptions. Currently : no other specialization than its name. 27 * 28 * @author etienne_sf 29 * @version $Revision: 887 $ 30 */ 31 public class JUploadException extends Exception { 32 /** A generated serialVersionUID, to avoid warning during compilation */ 33 private static final long serialVersionUID = -6386378085666411905L; 34 35 private String location = null; 36 37 /** 38 * Creates a new instance with a specified message. 39 * 40 * @param message The message to be associated with this instance. 41 */ 42 public JUploadException(String message) { 43 super(message); 44 StackTraceElement[] trace = super.getStackTrace(); 45 if (trace.length > 0) { 46 StackTraceElement se = trace[0]; 47 this.location = se.getClassName() + "." + se.getMethodName() 48 + " in " + se.getFileName() + ", line " 49 + se.getLineNumber(); 50 } 51 } 52 53 /** 54 * Creates a new instance with a specified original exception. 55 * 56 * @param ex The exception that was originally thrown. 57 */ 58 public JUploadException(Exception ex) { 59 super(ex); 60 StackTraceElement[] trace = ex.getStackTrace(); 61 if (trace.length > 0) { 62 StackTraceElement se = trace[0]; 63 this.location = se.getClassName() + "." + se.getMethodName() 64 + " in " + se.getFileName() + ", line " 65 + se.getLineNumber(); 66 } 67 } 68 69 /** 70 * Creates a new instance with a specified message and original exception. 71 * 72 * @param message The message to be associated with this instance. 73 * @param ex The exception that was originally thrown. 74 */ 75 public JUploadException(String message, Throwable ex) { 76 super(message, ex); 77 StackTraceElement[] trace = ex.getStackTrace(); 78 if (trace.length > 0) { 79 StackTraceElement se = trace[0]; 80 this.location = se.getClassName() + "." + se.getMethodName() 81 + " in " + se.getFileName() + ", line " 82 + se.getLineNumber(); 83 } 84 } 85 86 /** 87 * Retrieves the human readable location of this exception (Class.method, 88 * filename, linenumber) 89 * 90 * @return The location where this exception was thrown. 91 */ 92 public String getLocation() { 93 return (null == this.location) ? "unknown location" : this.location; 94 } 95 96 /** 97 * Returns JUploadExceptionClassName:CauseClassName. For instance:<BR> 98 * wjhk.jupload2.exception.JUploadIOException:FileNotFoundException <BR> 99 * or<BR> 100 * wjhk.jupload2.exception.JUploadIOException (if there is no cause given to 101 * the JUploadException constructor). 102 * 103 * @return The class name(s) that can be displayed in an error message. 104 */ 105 public String getClassNameAndClause() { 106 if (getCause() == null) { 107 return this.getClass().getName(); 108 } else { 109 return this.getClass().getName() + ":" 110 + this.getCause().getClass().getName(); 111 } 112 } 113 }