001 package org.shiftone.jrat.util; 002 003 004 import java.io.PrintWriter; 005 import java.io.StringWriter; 006 007 008 /** 009 * @author jeff@shiftone.org (Jeff Drost) 010 */ 011 public class Exceptions { 012 013 public static String printStackTrace(Throwable throwable) { 014 015 StringWriter stringWriter = new StringWriter(); 016 PrintWriter printWriter = new PrintWriter(stringWriter); 017 018 throwable.printStackTrace(printWriter); 019 printWriter.flush(); 020 021 return stringWriter.toString(); 022 } 023 024 025 public static RuntimeException wrapAsRTE(Throwable throwable) { 026 027 if (throwable instanceof RuntimeException) { 028 return (RuntimeException) throwable; 029 } else { 030 return new RuntimeException(throwable); 031 } 032 } 033 }