View Javadoc

1   /*
2    * Copyright (C) 2007 Alf Mikula
3    * 
4    * This file is part of PromoteGo.
5    *
6    * PromoteGo 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 3 of the License, or
9    * (at your option) any later version.
10   *
11   * PromoteGo is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with PromoteGo.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.promotego.exceptions;
20  
21  import java.io.PrintStream;
22  import java.io.PrintWriter;
23  
24  public class NestedException extends RuntimeException
25  {
26      private Exception m_exception;
27      
28      private NestedException(Exception e)
29      {
30          m_exception = e;
31      }
32      
33      public static NestedException wrap(Exception e)
34      {
35          if (e instanceof NestedException)
36          {
37              return (NestedException)e;
38          }
39          else
40          {
41              return new NestedException(e);
42          }
43      }
44  
45      public Throwable fillInStackTrace()
46      {
47          // This exception's stack trace will be masked anyway, so do nothing.
48          return this;
49      }
50  
51      // delegate all methods (except equals and hashCode) to underlying exception
52      public Throwable getCause()
53      {
54          return m_exception.getCause();
55      }
56  
57      public String getLocalizedMessage()
58      {
59          return m_exception.getLocalizedMessage();
60      }
61  
62      public String getMessage()
63      {
64          return m_exception.getMessage();
65      }
66  
67      public StackTraceElement[] getStackTrace()
68      {
69          return m_exception.getStackTrace();
70      }
71  
72      public Throwable initCause(Throwable cause)
73      {
74          return m_exception.initCause(cause);
75      }
76  
77      public void printStackTrace()
78      {
79          m_exception.printStackTrace();
80      }
81  
82      public void printStackTrace(PrintStream s)
83      {
84          m_exception.printStackTrace(s);
85      }
86  
87      public void printStackTrace(PrintWriter s)
88      {
89          m_exception.printStackTrace(s);
90      }
91  
92      public void setStackTrace(StackTraceElement[] stackTrace)
93      {
94          m_exception.setStackTrace(stackTrace);
95      }
96  
97      public String toString()
98      {
99          return m_exception.toString();
100     }
101 }