KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > util > jcache > CacheException


1 /* Open Source Java Caching Service
2 * Copyright (C) 2002 Frank Karlstrøm
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * The author can be contacted by email: fjankk@users.sourceforge.net
18 */

19 package javax.util.jcache;
20
21 /**
22  * An exception was caught or generated within the cache.
23  */

24 public class CacheException extends Exception JavaDoc {
25     /** the wrapped exception */
26     private final Exception JavaDoc base;
27     private String JavaDoc message;
28
29     /**
30      * Creates new <code>CacheException</code> without detail message.
31      */

32     public CacheException() {
33         this.base = null;
34     }
35
36     public String JavaDoc getLocalizedMessage() {
37         return message==null?super.getLocalizedMessage():message;
38     }
39     public String JavaDoc getMessage() {
40         return message==null?super.getMessage():message;
41     }
42     /**
43      * Constructs an <code>CacheException</code> with the specified detail
44      * Exception and additional message.
45      *
46      * @param message the detail message.
47      * @param cause the detail exception.
48      */

49     public CacheException(final String JavaDoc message, final Exception JavaDoc cause) {
50         super(message);
51         this.base = cause;
52     }
53
54     /**
55      * Constructs an <code>CacheException</code> with the specified detail
56      * Exception.
57      *
58      * @param cause the detail exception.
59      */

60     public CacheException(final Exception JavaDoc cause) {
61         super();
62         this.base = cause;
63     }
64
65     /**
66      * Constructs an <code>CacheException</code> with the specified detail
67      * message.
68      *
69      * @param msg the detail message.
70      */

71     public CacheException(final String JavaDoc msg) {
72         super(msg);
73         this.base = null;
74     }
75
76     /**
77      * prints the stacktrace for this Exception, and if an wrapped exception is
78      * in place, that stacktrace is also included.
79      *
80      * @see java.lang.Throwable#printStackTrace()
81      */

82     public final void printStackTrace() {
83         super.printStackTrace();
84         if (base != null) {
85             System.err.println("CAUSED BY:");
86             base.printStackTrace();
87         }
88     }
89
90     /**
91      * Gets the wrapped exception
92      *
93      * @return the wrapped exception
94      */

95     public final Exception JavaDoc getBase() {
96         return base;
97     }
98
99     public void setMessage(String JavaDoc message) {
100         this.message=message;
101     }
102 }
103
Popular Tags