KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > plankton > exceptions > NestableException


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: NestableException.java,v 1.3 2004/02/01 05:16:28 christianc Exp $
19  */

20 package org.enhydra.barracuda.plankton.exceptions;
21
22 /**
23  * This class simply defines a NestableException.
24  * A NestableException can contain other exceptions
25  * (which may have triggered this exception). The
26  * getRootException method provides a means to find the
27  * root exception in a NestableException chain.
28  */

29 public class NestableException extends Exception JavaDoc {
30
31     private Exception JavaDoc baseException = null;
32
33     /**
34      * The noargs public contructor for NestableException
35      */

36     public NestableException () {
37         this("Unidentified Exception");
38     }
39
40     /**
41      * The public contructor for NestableException
42      *
43      * @param s a String describing the exception
44      */

45     public NestableException (String JavaDoc s) {
46         this(s, null);
47     }
48
49     /**
50      * The public contructor for NestableException
51      *
52      * @param s a String describing the exception
53      * @param ibaseException the original exception to wrap within this exception
54      */

55     public NestableException (String JavaDoc s, Exception JavaDoc ibaseException) {
56         super(s);
57         baseException = ibaseException;
58     }
59
60     /**
61      * get the BaseException behind this exception
62      *
63      * @return Exception baseException
64      */

65     public Exception JavaDoc getBaseException () {
66         return baseException;
67     }
68
69     /**
70      * get the RootException behind this exception. Will look for
71      * a baseException, and if it happens to be an instance of a
72      * NestableException, will recursively work deeper until it finds
73      * the exception which caused it all
74      *
75      * @param ne a NestableException for which we wish to find
76      * the root exception
77      * @return Exception the exception which caused it all
78      */

79     public synchronized static Exception JavaDoc getRootException (NestableException ne) {
80         Exception JavaDoc e = ne.getBaseException();
81         if (e!=null && e instanceof NestableException) return getRootException ((NestableException) e);
82         return ne;
83     }
84 }
Popular Tags