1 package org.codehaus.plexus.util; 2 3 /* 4 * Copyright The Codehaus Foundation. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 import java.io.PrintWriter; 20 import java.io.StringWriter; 21 22 /** 23 * Convenience class to handle throwable stacktraces 24 * <p> 25 * Created on 18/06/2003 26 * </p> 27 * 28 * @author <a href="mailto:bert@tuaworks.co.nz">Bert van Brakel</a> 29 * @version $Id: $Id 30 * @since 3.4.0 31 */ 32 public class Tracer { 33 34 /** 35 * Constructor 36 */ 37 private Tracer() { 38 super(); 39 } 40 41 /** 42 * Return the throwable stack trace as a string 43 * 44 * @param t a {@link java.lang.Throwable} object. 45 * @return a {@link java.lang.String} object. 46 */ 47 public static String traceToString(Throwable t) { 48 if (t == null) { 49 return null; 50 } 51 StringWriter sw = new StringWriter(); 52 t.printStackTrace(new PrintWriter(sw)); 53 return sw.toString(); 54 } 55 }