KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > lang > SoftException


1 /* *******************************************************************
2  * Copyright (c) 1999-2001 Xerox Corporation,
3  * 2002 Palo Alto Research Center, Incorporated (PARC),
4  * 2004 Contributors.
5  * All rights reserved.
6  * This program and the accompanying materials are made available
7  * under the terms of the Eclipse Public License v1.0
8  * which accompanies this distribution and is available at
9  * http://www.eclipse.org/legal/epl-v10.html
10  *
11  * Contributors:
12  * Xerox/PARC initial implementation
13  * ******************************************************************/

14
15
16 package org.aspectj.lang;
17
18 import java.io.PrintStream JavaDoc;
19 import java.io.PrintWriter JavaDoc;
20
21 /**
22  * Wrapper for checked exceptions matched by a 'declare soft'.
23  * You can soften checked exceptions at join points by using
24  * the form <code>declare soft: TypePattern: Pointcut</code>.
25  * At the join points, any exceptions thrown which match
26  * TypePattern will be wrapped in <code>SoftException</code>
27  * and rethrown. You can get the original exception using
28  * <code>getWrappedThrowable()</code> or
29  * <code>getCause()</code>.
30  */

31 public class SoftException extends RuntimeException JavaDoc {
32
33     private static final boolean HAVE_JAVA_14;
34
35     static {
36         boolean java14 = false;
37         try {
38             Class.forName("java.nio.Buffer");
39             java14 = true;
40         } catch (Throwable JavaDoc t) {
41             // still false;
42
}
43         HAVE_JAVA_14 = java14;
44     }
45
46     // shouldn't field be private final, constructor default or private?
47
// but either would be a binary incompatible change.
48

49     Throwable JavaDoc inner;
50
51     public SoftException(Throwable JavaDoc inner) {
52         super();
53         this.inner = inner;
54     }
55     
56     public Throwable JavaDoc getWrappedThrowable() { return inner; }
57     public Throwable JavaDoc getCause() { return inner; }
58     
59     public void printStackTrace() {
60         printStackTrace(System.err);
61     }
62     
63     public void printStackTrace(PrintStream JavaDoc stream) {
64         super.printStackTrace(stream);
65         final Throwable JavaDoc _inner = this.inner;
66         if (!HAVE_JAVA_14 && (null != _inner)) {
67             stream.print("Caused by: ");
68             _inner.printStackTrace(stream);
69         }
70     }
71     
72     public void printStackTrace(PrintWriter JavaDoc stream) {
73         super.printStackTrace(stream);
74         final Throwable JavaDoc _inner = this.inner;
75         if (!HAVE_JAVA_14 && (null != _inner)) {
76             stream.print("Caused by: ");
77             _inner.printStackTrace(stream);
78         }
79     }
80 }
81
Popular Tags