001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.commons.discovery;
018
019
020 /**
021 * <p>An exception that is thrown only if a suitable service
022 * instance cannot be created by <code>ServiceFactory</code></p>
023 *
024 * <p>Copied from LogConfigurationException<p>
025 *
026 * @author Craig R. McClanahan
027 * @version $Revision: 480374 $ $Date: 2006-11-29 04:33:25 +0100 (Mi, 29. Nov 2006) $
028 */
029 public class DiscoveryException extends RuntimeException {
030
031
032 /**
033 * Construct a new exception with <code>null</code> as its detail message.
034 */
035 public DiscoveryException() {
036 super();
037 }
038
039 /**
040 * Construct a new exception with the specified detail message.
041 *
042 * @param message The detail message
043 */
044 public DiscoveryException(String message) {
045 super(message);
046 }
047
048 /**
049 * Construct a new exception with the specified cause and a derived
050 * detail message.
051 *
052 * @param cause The underlying cause
053 */
054 public DiscoveryException(Throwable cause) {
055 this((cause == null) ? null : cause.toString(), cause);
056 }
057
058 /**
059 * Construct a new exception with the specified detail message and cause.
060 *
061 * @param message The detail message
062 * @param cause The underlying cause
063 */
064 public DiscoveryException(String message, Throwable cause) {
065 super(message);
066 this.cause = cause; // Two-argument version requires JDK 1.4 or later
067 }
068
069 /**
070 * The underlying cause of this exception.
071 */
072 protected Throwable cause = null;
073
074 /**
075 * Return the underlying cause of this exception (if any).
076 */
077 public Throwable getCause() {
078 return this.cause;
079 }
080
081 public String toString() {
082 String ls = System.getProperty("line.separator");
083 String str = super.toString();
084 if (cause != null) {
085 str = str + ls +
086 "*****" + ls +
087 stackToString(cause);
088 }
089 return str;
090 }
091
092 private static String stackToString(Throwable e){
093 java.io.StringWriter sw= new java.io.StringWriter(1024);
094 java.io.PrintWriter pw= new java.io.PrintWriter(sw);
095 e.printStackTrace(pw);
096 pw.close();
097 return sw.toString();
098 }
099 }