1 | // jademx - JADE management using JMX |
2 | // Copyright 2005 Caboodle Networks, Inc. |
3 | // |
4 | // This library is free software; you can redistribute it and/or |
5 | // modify it under the terms of the GNU Lesser General Public |
6 | // License as published by the Free Software Foundation; either |
7 | // version 2.1 of the License, or (at your option) any later version. |
8 | // |
9 | // This library is distributed in the hope that it will be useful, |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | // Lesser General Public License for more details. |
13 | // |
14 | // You should have received a copy of the GNU Lesser General Public |
15 | // License along with this library; if not, write to the Free Software |
16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
17 | |
18 | package jade.jademx.util; |
19 | |
20 | //import jade.util.Logger; |
21 | |
22 | import java.io.PrintWriter; |
23 | import java.io.StringWriter; |
24 | |
25 | /** |
26 | * Throwable utility class. |
27 | * @author David Bernstein, <a href="http://www.caboodlenetworks.com" |
28 | * >Caboodle Networks, Inc.</a> |
29 | */ |
30 | public class ThrowableUtil { |
31 | |
32 | /** |
33 | * private to prevent instantiation |
34 | */ |
35 | private ThrowableUtil() { |
36 | } |
37 | |
38 | /** |
39 | * convenience method to put stack trace in a string |
40 | * @param t throwable to get stack trace for |
41 | * @return throwable's stack trace as a string |
42 | */ |
43 | public static String stackTrace( Throwable t ) { |
44 | String s = null; |
45 | if ( null != t ) { |
46 | StringWriter sw = new StringWriter(); |
47 | PrintWriter pw = new PrintWriter( sw ); |
48 | t.printStackTrace( pw ); |
49 | s = sw.toString(); |
50 | } |
51 | return s; |
52 | } |
53 | |
54 | /** |
55 | * return message with throwable stack trace appended to i |
56 | * @param message message to return |
57 | * @param t throwable whose stack trace to include |
58 | * @return message with throwable stack trace appended to i |
59 | */ |
60 | public static String errMsg( String message, Throwable t ) { |
61 | return message + "\n" + stackTrace( t ); |
62 | } |
63 | |
64 | } |