01: /*
02: * Copyright (c) 2002-2006 by OpenSymphony
03: * All rights reserved.
04: */
05:
06: package com.opensymphony.xwork.interceptor;
07:
08: import java.io.IOException;
09: import java.io.PrintWriter;
10: import java.io.StringWriter;
11:
12: /**
13: * <!-- START SNIPPET: javadoc -->
14: *
15: * A simple wrapper around an exception, providing an easy way to print out the stack trace of the exception as well as
16: * a way to get a handle on the exception itself.
17: *
18: * <!-- END SNIPPET: javadoc -->
19: *
20: * @author Matthew E. Porter (matthew dot porter at metissian dot com) Date: Sep 21, 2005 Time: 3:09:12 PM
21: */
22: public class ExceptionHolder {
23: private Exception exception;
24:
25: public ExceptionHolder(Exception exception) {
26: this .exception = exception;
27: }
28:
29: public Exception getException() {
30: return this .exception;
31: }
32:
33: public String getExceptionStack() throws IOException {
34: String exceptionStack = null;
35:
36: if (getException() != null) {
37: StringWriter sw = new StringWriter();
38: PrintWriter pw = new PrintWriter(sw);
39:
40: try {
41: getException().printStackTrace(pw);
42: exceptionStack = sw.toString();
43: } finally {
44: sw.close();
45: pw.close();
46: }
47: }
48:
49: return exceptionStack;
50: }
51: }
|