001 package com.softnetConsult.utils.exceptions;
002
003 import java.io.ByteArrayOutputStream;
004 import java.io.PrintWriter;
005
006 /**
007 * This is a collection of static utility methods for dealing with exceptions
008 * and other {@code Throwable} objects.
009 *
010 * <p style="font-size:smaller;">This product includes software developed by the
011 * <strong>SoftNet-Consult Java Utility Library</strong> project and its contributors.<br />
012 * (<a href="http://java-tools.sourceforge.net" target="_blank">http://java-tools.sourceforge.net</a>)<br />
013 * Copyright (c) 2007-2008 SoftNet-Consult.<br />
014 * Copyright (c) 2007-2008 G. Paperin.<br />
015 * All rights reserved.
016 * </p>
017 * <p style="font-size:smaller;">File: ThrowableTools.java<br />
018 * Library API version: {@value com.softnetConsult.utils.APIProperties#apiVersion}<br />
019 * Java compliance version: {@value com.softnetConsult.utils.APIProperties#javaComplianceVersion}
020 * </p>
021 * <p style="font-size:smaller;">Redistribution and use in source and binary forms, with or
022 * without modification, are permitted provided that the following terms and conditions are met:
023 * </p>
024 * <p style="font-size:smaller;">1. Redistributions of source code must retain the above
025 * acknowledgement of the SoftNet-Consult Java Utility Library project, the above copyright
026 * notice, this list of conditions and the following disclaimer.<br />
027 * 2. Redistributions in binary form must reproduce the above acknowledgement of the
028 * SoftNet-Consult Java Utility Library project, the above copyright notice, this list of
029 * conditions and the following disclaimer in the documentation and/or other materials
030 * provided with the distribution.<br />
031 * 3. All advertising materials mentioning features or use of this software or any derived
032 * software must display the following acknowledgement:<br />
033 * <em>This product includes software developed by the SoftNet-Consult Java Utility Library
034 * project and its contributors.</em>
035 * </p>
036 * <p style="font-size:smaller;">THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY
037 * OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
038 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
039 * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
040 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
041 * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
042 * </p>
043 * @author Greg Paperin (<a href="http://www.paperin.org" target="_blank">http://www.paperin.org</a>)
044 * @version {@value com.softnetConsult.utils.APIProperties#apiVersion}
045 */
046 public final class ThrowableTools {
047
048 /**
049 * Prevents instances of this class from being created
050 * as this class contains only static utility methods.
051 */
052 private ThrowableTools() {}
053
054 /**
055 * Returns the output of the {@code printStackTrace}-method of the specified object
056 * in form of a string.
057 *
058 * @param e A throwable object.
059 * @return The output of {@code e.printStackTrace()} as a string;
060 */
061 public static String stackTraceToString(Throwable e) {
062 ByteArrayOutputStream outBuff = new ByteArrayOutputStream();
063 PrintWriter out = new PrintWriter(outBuff, true);
064 e.printStackTrace(out);
065 String s = outBuff.toString();
066 out.close();
067 return s;
068 }
069
070 } // public class ThrowableTools