01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.commons.discovery;
18:
19: /**
20: * <p>An exception that is thrown only if a suitable service
21: * instance cannot be created by <code>ServiceFactory</code></p>
22: *
23: * <p>Copied from LogConfigurationException<p>
24: *
25: * @author Craig R. McClanahan
26: * @version $Revision: 480374 $ $Date: 2006-11-28 19:33:25 -0800 (Tue, 28 Nov 2006) $
27: */
28: public class DiscoveryException extends RuntimeException {
29:
30: /**
31: * Construct a new exception with <code>null</code> as its detail message.
32: */
33: public DiscoveryException() {
34: super ();
35: }
36:
37: /**
38: * Construct a new exception with the specified detail message.
39: *
40: * @param message The detail message
41: */
42: public DiscoveryException(String message) {
43: super (message);
44: }
45:
46: /**
47: * Construct a new exception with the specified cause and a derived
48: * detail message.
49: *
50: * @param cause The underlying cause
51: */
52: public DiscoveryException(Throwable cause) {
53: this ((cause == null) ? null : cause.toString(), cause);
54: }
55:
56: /**
57: * Construct a new exception with the specified detail message and cause.
58: *
59: * @param message The detail message
60: * @param cause The underlying cause
61: */
62: public DiscoveryException(String message, Throwable cause) {
63: super (message);
64: this .cause = cause; // Two-argument version requires JDK 1.4 or later
65: }
66:
67: /**
68: * The underlying cause of this exception.
69: */
70: protected Throwable cause = null;
71:
72: /**
73: * Return the underlying cause of this exception (if any).
74: */
75: public Throwable getCause() {
76: return this .cause;
77: }
78:
79: public String toString() {
80: String ls = System.getProperty("line.separator");
81: String str = super .toString();
82: if (cause != null) {
83: str = str + ls + "*****" + ls + stackToString(cause);
84: }
85: return str;
86: }
87:
88: private static String stackToString(Throwable e) {
89: java.io.StringWriter sw = new java.io.StringWriter(1024);
90: java.io.PrintWriter pw = new java.io.PrintWriter(sw);
91: e.printStackTrace(pw);
92: pw.close();
93: return sw.toString();
94: }
95: }
|