View Javadoc
1   package org.apache.fulcrum.yaafi.framework.util;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.PrintWriter;
23  import java.io.StringWriter;
24  
25  /**
26   * A subset of the utilities available in commons-lang-2.1 ExceptionUtils.
27   *
28   * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
29   */
30  public class ExceptionUtils
31  {
32  
33      /**
34       * <p>Public constructor allows an instance of <code>ExceptionUtils</code>
35       * to be created, although that is not normally necessary.</p>
36       */
37      public ExceptionUtils()
38      {
39          // nothing to do
40      }
41  
42      /**
43       * <p>Gets the stack trace from a Throwable as a String.</p>
44       *
45       * @param throwable  the <code>Throwable</code> to be examined
46       * @return the stack trace as generated by the exception's
47       *  <code>printStackTrace(PrintWriter)</code> method
48       */
49      public static String getStackTrace(Throwable throwable)
50      {
51          StringWriter sw = new StringWriter();
52          PrintWriter pw = new PrintWriter( sw, true );
53          throwable.printStackTrace( pw );
54          return sw.getBuffer().toString();
55      }
56  }