| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| RethrowableRuntimeException |
|
| 1.6666666666666667;1.667 |
| 1 | /* | |
| 2 | * RethrowableException.java -- class for wrapping exceptions | |
| 3 | * Copyright (C) 1999 Quiotix Corporation. | |
| 4 | * All rights reserved. | |
| 5 | * | |
| 6 | * Redistribution and use in source and binary forms, with or without | |
| 7 | * modification, are permitted provided that the following conditions are | |
| 8 | * met: | |
| 9 | * | |
| 10 | * Redistributions of source code must retain the above copyright | |
| 11 | * notice, this list of conditions and the following disclaimer. | |
| 12 | * | |
| 13 | * Neither name of Quiotix Corporation nor the names of its | |
| 14 | * contributors may be used to endorse or promote products derived from | |
| 15 | * this software without specific prior written permission. | |
| 16 | * | |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 21 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 22 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 23 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 28 | */ | |
| 29 | ||
| 30 | package org.webmacro; | |
| 31 | ||
| 32 | /** | |
| 33 | * RethrowableRuntimeException | |
| 34 | * | |
| 35 | * A standard exception, inherited from RuntimeException, which also | |
| 36 | * includes a constructor of the form Exception(String, Exception) | |
| 37 | * which allows one exception to wrap another without throwing away | |
| 38 | * useful debugging information. The PrintStackTrace routine will | |
| 39 | * print the stack trace for both the original exception and the point | |
| 40 | * at which the exception was rethrown. | |
| 41 | * | |
| 42 | * @author Brian Goetz (Quiotix Corp) | |
| 43 | * @since 0.96 */ | |
| 44 | public class RethrowableRuntimeException extends RuntimeException | |
| 45 | { | |
| 46 | ||
| 47 | private static final long serialVersionUID = 1L; | |
| 48 | ||
| 49 | private Throwable cause; | |
| 50 | ||
| 51 | private final static String RETHROW_MESSAGE = "-- secondary stack trace --"; | |
| 52 | ||
| 53 | public RethrowableRuntimeException () | |
| 54 | { | |
| 55 | 0 | super(); |
| 56 | 0 | } |
| 57 | ||
| 58 | public RethrowableRuntimeException (String s) | |
| 59 | { | |
| 60 | 0 | super(s); |
| 61 | 0 | } |
| 62 | ||
| 63 | public RethrowableRuntimeException (String s, Throwable e) | |
| 64 | { | |
| 65 | 0 | super(s + System.getProperty("line.separator") + e); |
| 66 | 0 | cause = e; |
| 67 | 0 | while (cause instanceof RethrowableRuntimeException) |
| 68 | { | |
| 69 | 0 | cause = ((RethrowableRuntimeException) cause).cause; |
| 70 | } | |
| 71 | 0 | } |
| 72 | ||
| 73 | public void printStackTrace () | |
| 74 | { | |
| 75 | 0 | super.printStackTrace(); |
| 76 | 0 | if (cause != null) |
| 77 | { | |
| 78 | 0 | System.err.println(RETHROW_MESSAGE); |
| 79 | 0 | cause.printStackTrace(); |
| 80 | } | |
| 81 | 0 | } |
| 82 | ||
| 83 | public void printStackTrace (java.io.PrintStream ps) | |
| 84 | { | |
| 85 | 0 | super.printStackTrace(ps); |
| 86 | 0 | if (cause != null) |
| 87 | { | |
| 88 | 0 | ps.println(RETHROW_MESSAGE); |
| 89 | 0 | cause.printStackTrace(ps); |
| 90 | } | |
| 91 | 0 | } |
| 92 | ||
| 93 | public void printStackTrace (java.io.PrintWriter pw) | |
| 94 | { | |
| 95 | 0 | super.printStackTrace(pw); |
| 96 | 0 | if (cause != null) |
| 97 | { | |
| 98 | 0 | pw.println(RETHROW_MESSAGE); |
| 99 | 0 | cause.printStackTrace(pw); |
| 100 | } | |
| 101 | 0 | } |
| 102 | ||
| 103 | /** | |
| 104 | * allow access to underlying exception | |
| 105 | * @deprecated you should use <code>getCause</code> instead | |
| 106 | */ | |
| 107 | public Throwable getCaught () | |
| 108 | { | |
| 109 | 0 | return getCause(); |
| 110 | } | |
| 111 | ||
| 112 | /** | |
| 113 | * Return the underlying exception provided at construction time | |
| 114 | * or null if none was provided. | |
| 115 | * @return underlying cause | |
| 116 | * @since 1.1 | |
| 117 | */ | |
| 118 | public Throwable getCause () | |
| 119 | { | |
| 120 | 0 | return cause; |
| 121 | } | |
| 122 | ||
| 123 | /** | |
| 124 | * Return the original exception cause. This will recursively | |
| 125 | * extract the cause if cause is a subclass of | |
| 126 | * <code>RethrowableException</code>. | |
| 127 | * @return underlying root cause | |
| 128 | * @since 1.1 | |
| 129 | */ | |
| 130 | public Throwable getRootCause () | |
| 131 | { | |
| 132 | 0 | Throwable t = cause; |
| 133 | 0 | while (t != null && t instanceof RethrowableRuntimeException) |
| 134 | { | |
| 135 | 0 | t = ((RethrowableRuntimeException) t).cause; |
| 136 | } | |
| 137 | 0 | return t; |
| 138 | } | |
| 139 | } |