1 /* 2 ExceptionUtils.java 3 Creation date : 17/06/2011 4 Copyright © Benjamin Croizet (graffity2199@yahoo.fr) 5 6 This program is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License 8 or GNU Lesser General Public License as published by the 9 Free Software Foundation; either version 3 of the License, 10 or (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received copies of the GNU General Public License 18 and GNU Lesser General Public License along with this program; 19 if not, write to the Free Software Foundation, Inc., 20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 http://www.fsf.org/licensing/licenses/gpl.html 22 http://www.gnu.org/licenses/lgpl.html 23 */ 24 25 package net.sourceforge.plantumldependency.common.utils.exception; 26 27 import java.io.PrintWriter; 28 import java.io.StringWriter; 29 import java.io.Writer; 30 31 /** 32 * The class utilities for Exception. 33 * 34 * @author Benjamin Croizet (<a href="mailto:graffity2199@yahoo.fr>graffity2199@yahoo.fr</a>) 35 * @since 1.3.0 36 * @version 1.3.0 37 */ 38 public abstract class ExceptionUtils { 39 40 /** 41 * Gets the stack strace of an exception as a {@link String}. 42 * 43 * @param throwable 44 * the {@link Throwable} to get the stack trace from, mustn't be <code>null</code>. 45 * @return the stack trace of the exception as a {@link String}. 46 * @since 1.3.0 47 */ 48 public static String getStackTraceAsString(final Throwable throwable) { 49 final Writer result = new StringWriter(); 50 final PrintWriter printWriter = new PrintWriter(result); 51 throwable.printStackTrace(printWriter); 52 return result.toString(); 53 } 54 55 /** 56 * Private constructor to prevent from instantiation. 57 * 58 * @since 1.3.0 59 */ 60 private ExceptionUtils() { 61 super(); 62 } 63 }