Source code: edu/iicm/xpg/statemachine/TransitionException.java
1 /***********************************************************************
2 * @(#)$RCSfile: TransitionException.java,v $
3 *
4 * Copyright (c) 2001 IICM, Graz University of Technology
5 * Schiesstattgasse 4a, A-8010 Graz, Austria.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License (LGPL)
9 * as published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to the
19 * Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 ***********************************************************************/
22
23 package edu.iicm.xpg.statemachine;
24
25 //----------------------------------------------------------------------
26 /**
27 * @author Stefan Thalauer
28 * @version $Revision: 1.1 $
29 */
30
31
32 public class TransitionException extends Exception
33 {
34 protected Exception exception_;
35
36 //----------------------------------------------------------------------
37 /**
38 */
39
40 public TransitionException ()
41 {
42 super();
43 exception_ = null;
44 }
45
46
47 //----------------------------------------------------------------------
48 /**
49 */
50
51 public TransitionException (String message)
52 {
53 super(message);
54 exception_ = null;
55 }
56
57 //----------------------------------------------------------------------
58 /** Create a new TransitionException wrapping an existing exception.
59 *
60 * The existing exception will be embedded in the new
61 * one, and its message will become the default message for
62 * the TransitionException.
63 *
64 * @param exc The exception to be wrapped in a TransitionException.
65 */
66
67 public TransitionException (Exception exc)
68 {
69 super();
70 exception_ = exc;
71 }
72
73 //----------------------------------------------------------------------
74 /** Create a new TransitionException from an existing exception.
75 *
76 * The existing exception will be embedded in the new
77 * one, but the new exception will have its own message.
78 *
79 * @param message The detail message.
80 * @param exc The exception to be wrapped in a TransitionException.
81 */
82
83 public TransitionException (String message, Exception exc)
84 {
85 super(message);
86 exception_ = exc;
87 }
88
89 //----------------------------------------------------------------------
90 /** Return a detail message for this exception.
91 *
92 * If there is an embedded exception, and if the TransitionException
93 * has no detail message of its own, this method will return
94 * the detail message from the embedded exception.</p>
95 *
96 * @return The error or warning message.
97 */
98 public String getMessage ()
99 {
100 String message = super.getMessage();
101
102 if (message == null && exception_ != null)
103 {
104 return exception_.getMessage();
105 }
106 else
107 {
108 return message;
109 }
110 }
111
112 //----------------------------------------------------------------------
113 /** Return the embedded exception, if any.
114 *
115 * @return The embedded exception, or null if there is none.
116 */
117
118 public Exception getException ()
119 {
120 return exception_;
121 }
122
123 //----------------------------------------------------------------------
124 /** Override toString to pick up any embedded exception.
125 *
126 * @return A string representation of this exception.
127 */
128
129 public String toString ()
130 {
131 if (exception_ != null)
132 {
133 return exception_.toString();
134 }
135 else
136 {
137 return super.toString();
138 }
139 }
140 }
141