KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > common > util > WrappedException


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: WrappedException.java,v 1.3 2005/06/08 06:19:08 nickb Exp $
16  */

17 package org.eclipse.emf.common.util;
18
19 import java.io.PrintStream JavaDoc;
20 import java.io.PrintWriter JavaDoc;
21
22
23 /**
24  * A runtime exception that wraps another exception.
25  */

26 public class WrappedException extends RuntimeException JavaDoc
27 {
28   /**
29    * The exception being wrapped.
30    */

31   protected Exception JavaDoc wrappedException;
32
33   /**
34    * Creates an instance that wraps the exception.
35    */

36   public WrappedException(Exception JavaDoc exception)
37   {
38     super(exception.getLocalizedMessage());
39     wrappedException = exception;
40   }
41
42   /**
43    * Creates an instance with it's own message that wraps the exception.
44    * @param message the message.
45    * @param exception the exception to wrap.
46    */

47   public WrappedException(String JavaDoc message, Exception JavaDoc exception)
48   {
49     super(message);
50     wrappedException = exception;
51   }
52
53   /**
54    * Returns the wrapped exception.
55    * @return the wrapped exception.
56    */

57   public Exception JavaDoc exception()
58   {
59     return wrappedException;
60   }
61
62   /**
63    * Prints both wrapped exception's stack and this one's.
64    */

65   public void printStackTrace()
66   {
67     System.err.println("Wrapped exception");
68     wrappedException.printStackTrace();
69     System.err.println("Wrapped by");
70     super.printStackTrace();
71   }
72
73   /**
74    * Prints both wrapped exception's stack and this one's.
75    * @param printStream the print target.
76    */

77   public void printStackTrace(PrintStream JavaDoc printStream)
78   {
79     printStream.println("Wrapped exception");
80     wrappedException.printStackTrace(printStream);
81     printStream.println("Wrapped by");
82     super.printStackTrace(printStream);
83   }
84
85   /**
86    * Prints both wrapped exception's stack and this one's.
87    * @param printWriter the print target.
88    */

89   public void printStackTrace(PrintWriter JavaDoc printWriter)
90   {
91     printWriter.println("Wrapped exception");
92     wrappedException.printStackTrace(printWriter);
93     printWriter.println("Wrapped by");
94     super.printStackTrace(printWriter);
95   }
96 }
97
Popular Tags