Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/lutris/util/ChainedRuntimeException.java


1   /*
2    * Enhydra Java Application Server Project
3    * 
4    * The contents of this file are subject to the Enhydra Public License
5    * Version 1.1 (the "License"); you may not use this file except in
6    * compliance with the License. You may obtain a copy of the License on
7    * the Enhydra web site ( http://www.enhydra.org/ ).
8    * 
9    * Software distributed under the License is distributed on an "AS IS"
10   * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 
11   * the License for the specific terms governing rights and limitations
12   * under the License.
13   * 
14   * The Initial Developer of the Enhydra Application Server is Lutris
15   * Technologies, Inc. The Enhydra Application Server and portions created
16   * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17   * All Rights Reserved.
18   * 
19   * Contributor(s):
20   * 
21   * $Id: ChainedRuntimeException.java,v 1.3.12.1 2000/10/19 17:58:53 jasona Exp $
22   */
23  
24  package com.lutris.util;
25  
26  import java.io.*;
27  
28  /**
29   * RuntimeException used as a base for creating an exception that has a chain
30   * of exceptions that lead to the derived exception.  Very useful for
31   * interfaces where the implementation exception is not known.
32   */
33  public class ChainedRuntimeException extends RuntimeException implements ChainedThrowable {
34      private Throwable cause;
35  
36      /**
37       * Construct an exception without a specified cause.
38       *
39       * @param msg The message associated with the exception.
40       */
41      public ChainedRuntimeException(String msg) {
42          super(msg);
43          cause = null;
44      }
45  
46      /**
47       * Construct an exception with an associated causing exception.
48       *
49       * @param msg The message associated with the exception.
50       * @param cause The error or exception that cause this
51       *  exception.
52       */
53      public ChainedRuntimeException(String msg,
54                              Throwable cause) {
55          super(msg);
56          this.cause = cause;
57      }
58  
59      /**
60       * Construct an exception from a causing exception.
61       *
62       * @param cause The error or exception that cause this
63       *  exception. The message will be take be this object's
64       *  messasge.
65       */
66      public ChainedRuntimeException(Throwable cause) {
67          super(ChainedThrowableUtil.makeMessage(cause));
68          this.cause = cause;
69      }
70  
71      /**
72       * Return the message associated with this exception.  If causes
73       * are included, they will be appended to the message.
74       */
75      public String getMessage() {
76          return ChainedThrowableUtil.getMessage(this, super.getMessage());
77      }
78  
79      /**
80       * Get the causing exception associated with this exception.
81       * @return The causing exception or null if no cause is specified.
82       */
83      public Throwable getCause() {
84          return cause;
85      }
86  
87      /**
88       * Prints this ChainedRuntimeException and its backtrace, and the causes
89       * and their stack traces to the standard error stream. 
90       */
91      public void printStackTrace() {
92          super.printStackTrace();
93          ChainedThrowableUtil.printCauseTrace(this);
94      }
95  
96      /**
97       * Prints this ChainedRuntimeException and its backtrace, and the causes
98       * and their stack traces to the e specified print stream. 
99       */
100     public void printStackTrace(PrintStream s) {
101         super.printStackTrace(s);
102         ChainedThrowableUtil.printCauseTrace(this, s);
103     }
104 
105     /**
106      * Prints this ChainedRuntimeException and its backtrace, and the causes
107      * and their stack traces to the e specified print writer. 
108      */
109     public void printStackTrace(PrintWriter s) {
110         super.printStackTrace(s);
111         ChainedThrowableUtil.printCauseTrace(this, s);
112     }
113 }