Source code: gnu/javax/crypto/key/KeyAgreementException.java
1 /* KeyAgreementException.java --
2 Copyright (C) 2003, 2006 Free Software Foundation, Inc.
3
4 This file is a part of GNU Classpath.
5
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at
9 your option) any later version.
10
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19 USA
20
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
25
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
37
38
39 package gnu.javax.crypto.key;
40
41 import java.io.PrintStream;
42 import java.io.PrintWriter;
43 import java.io.Serializable;
44 import java.security.KeyManagementException;
45
46 /**
47 * A generic exception indicating that an unexpected condition has
48 * been detected during the setup and/or processing of a key agreement
49 * protocol exchange.
50 */
51 public class KeyAgreementException extends KeyManagementException implements
52 Serializable
53 {
54
55 // Constants and variables
56 // -------------------------------------------------------------------------
57
58 /** @serial The possibly <code>null</code> <i>root</i> cause exception. */
59 private Throwable cause = null;
60
61 // Constructor(s)
62 // -------------------------------------------------------------------------
63
64 /**
65 * <p>Constructs a new instance of <code>KeyAgreementException</code>. The
66 * root exception and the detailed message are <code>null</code>.</p>
67 */
68 public KeyAgreementException()
69 {
70 super();
71 }
72
73 /**
74 * <p>Constructs a new instance of <code>KeyAgreementException</code> with a
75 * detailed message. The <i>root</i> exception is <code>null</code>.</p>
76 *
77 * @param detail a possibly <code>null</code> string containing details of
78 * the exception.
79 * @see Throwable#getMessage()
80 */
81 public KeyAgreementException(String detail)
82 {
83 super(detail);
84 }
85
86 /**
87 * <p>Constructs a new instance of <code>KeyAgreementException</code> with a
88 * detailed message and a <i>root</i> exception.</p>
89 *
90 * @param detail a possibly <code>null</code> string containing details of
91 * the exception.
92 * @param cause a possibly <code>null</code> root exception that caused this
93 * exception.
94 * @see Throwable#getMessage()
95 * @see #getCause()
96 */
97 public KeyAgreementException(String detail, Throwable cause)
98 {
99 super(detail);
100 this.cause = cause;
101 }
102
103 // Class methods
104 // -------------------------------------------------------------------------
105
106 // Instance methods
107 // -------------------------------------------------------------------------
108
109 /**
110 * <p>Returns the cause of this throwable or <code>null</code> if the cause
111 * is nonexistent or unknown. The <i>cause</i> is the throwable that caused
112 * this exception to be thrown.</p>
113 *
114 * @return the possibly <code>null</code> exception that caused this one.
115 */
116 public Throwable getCause()
117 {
118 return cause;
119 }
120
121 /**
122 * <p>Prints this exception's stack trace to <code>System.err</code>. If this
123 * exception has a <i>root</i> exception; the stack trace of the <i>root</i>
124 * exception is also printed to <code>System.err</code>.</p>
125 */
126 public void printStackTrace()
127 {
128 super.printStackTrace();
129 if (cause != null)
130 {
131 cause.printStackTrace();
132 }
133 }
134
135 /**
136 * <p>Prints this exception's stack trace to a print stream. If this
137 * exception has a <i>root</i> exception; the stack trace of the <i>root</i>
138 * exception is also printed to the print stream.</p>
139 *
140 * @param ps the non-null print stream to which to print.
141 */
142 public void printStackTrace(PrintStream ps)
143 {
144 super.printStackTrace(ps);
145 if (cause != null)
146 {
147 cause.printStackTrace(ps);
148 }
149 }
150
151 /**
152 * <p>Prints this exception's stack trace to a print writer. If this
153 * exception has a <i>root</i> exception; the stack trace of the <i>root</i>
154 * exception is also printed to the print writer.</p>
155 *
156 * @param pw the non-null print writer to use for output.
157 */
158 public void printStackTrace(PrintWriter pw)
159 {
160 super.printStackTrace(pw);
161 if (cause != null)
162 {
163 cause.printStackTrace(pw);
164 }
165 }
166
167 /**
168 * <p>Returns the string representation of this exception. The string
169 * representation contains this exception's class name, its detailed
170 * messsage, and if it has a <i>root</i> exception, the string representation
171 * of the root exception. This string representation is meant for debugging
172 * and is not meant to be interpreted programmatically.</p>
173 *
174 * @return the non-null string representation of this exception.
175 * @see Throwable#getMessage()
176 */
177 public String toString()
178 {
179 StringBuffer sb = new StringBuffer(this.getClass().getName()).append(": ").append(
180 super.toString());
181 if (cause != null)
182 {
183 sb.append("; caused by: ").append(cause.toString());
184 }
185 return sb.toString();
186 }
187 }