001 /* 002 Copyright (C) 2001 Renaud Pawlak <renaud@aopsys.com> 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, but 010 WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public 015 License along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 017 USA */ 018 019 package org.objectweb.jac.util; 020 021 import java.lang.reflect.InvocationTargetException; 022 023 024 025 /** 026 * This runtime exeption wraps a regular exception so that JAC objects 027 * can also send non-runtime exceptions. 028 * 029 * @author <a href="mailto:pawlak@cnam.fr">Renaud Pawlak</a> 030 */ 031 032 public class WrappedThrowableException extends RuntimeException { 033 034 /** Strores the throwable object that is wrapped by this runtime 035 exception. */ 036 private Throwable wrappedThrowable; 037 038 /** 039 * Creates the wrapping exception.<p> 040 * 041 * @param wrappedThrowable the throwable that is wrapped by this 042 * exception */ 043 044 public WrappedThrowableException(Throwable wrappedThrowable) { 045 if (wrappedThrowable instanceof InvocationTargetException) { 046 this.wrappedThrowable = 047 ((InvocationTargetException)wrappedThrowable).getTargetException(); 048 } else { 049 this.wrappedThrowable = wrappedThrowable; 050 } 051 } 052 053 /** 054 * Gets the wrapped throwable. 055 * 056 * @return the wrapped throwable */ 057 058 public Throwable getWrappedThrowable() { 059 return wrappedThrowable; 060 } 061 062 /** 063 * Returns the string depicting the exception. It is the message of 064 * the wrapped throwable.<p> 065 * 066 * @return the printable representation of the wrapped exception */ 067 068 public String toString() { 069 return "WrappedThrowableException("+wrappedThrowable.toString()+")"; 070 } 071 072 /** 073 * Prints the stack trace that has been filled when the exception 074 * was created.<p> 075 * 076 * This method delegates to the wrapped throwable.<p> */ 077 078 public void printStackTrace() { 079 wrappedThrowable.printStackTrace(); 080 } 081 082 /** 083 * Prints the wrapped throwable and its backtrace to the 084 * specified print stream. 085 * 086 * @param s the stream */ 087 088 public void printStackTrace(java.io.PrintStream s) { 089 wrappedThrowable.printStackTrace(s); 090 } 091 092 /** 093 * Prints the wrapped throwable and its backtrace to the 094 * specified print writer. 095 * 096 * @param s the writer */ 097 098 public void printStackTrace(java.io.PrintWriter s) { 099 wrappedThrowable.printStackTrace(s); 100 } 101 102 /** 103 * Returns the error message string of the wrapped throwable 104 * object.<p> 105 * 106 * @return the error message string */ 107 108 public String getMessage() { 109 return wrappedThrowable.getMessage(); 110 } 111 112 public String getLocalizedMessage() { 113 return wrappedThrowable.getLocalizedMessage(); 114 } 115 116 /* 117 public StackTraceElement[] getStackTrace() { 118 System.out.println("*************** getWrapped stacktrace"); 119 return wrappedThrowable.getStackTrace(); 120 } 121 122 public Throwable getCause() { 123 return wrappedThrowable.getCause(); 124 } 125 */ 126 127 } 128 129 130 131 132