/*
 * @(#)StackTrace.java    2.6.0   29 May 2007
 *
 * Copyright 2007
 * College of Computer and Information Science
 * Northeastern University
 * Boston, MA  02115
 *
 * The Java Power Tools software may be used for educational
 * purposes as long as this copyright notice is retained intact
 * at the top of all source files.
 *
 * To discuss possible commercial use of this software, 
 * contact Richard Rasala at Northeastern University, 
 * College of Computer and Information Science,
 * 617-373-2462 or rasala@ccs.neu.edu.
 *
 * The Java Power Tools software has been designed and built
 * in collaboration with Viera Proulx and Jeff Raab.
 *
 * Should this software be modified, the words "Modified from 
 * Original" must be included as a comment below this notice.
 *
 * All publication rights are retained.  This software or its 
 * documentation may not be published in any media either
 * in whole or in part without explicit permission.
 *
 * This software was created with support from Northeastern 
 * University and from NSF grant DUE-9950829.
 */

package edu.neu.ccs.util;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * Class <code>StackTrace</code> provides a static
 * method to return the stack trace of a
 * <code>Throwable</code> as a <code>String</code>.
 */
public class StackTrace {
    
    /**
     * <p>Returns the stack trace of the given
     * <code>Throwable</code> as a <code>String</code>.</p>
     * 
     * <p>If the given throwable is <code>null</code>,
     * the string returned is an error message.</p>
     * 
     * @param t the <code>Throwable</code>
     */
    public static String getTrace(Throwable t) {
        if (t == null)
            return "Null Throwable passed to StackTrace.getTrace";
        
        StringWriter writer = new StringWriter();
        
        PrintWriter printwriter = new PrintWriter(writer);
        
        t.printStackTrace(printwriter);
        
        return writer.toString();
    }
    
}

