View Javadoc

1   package es.inteco.eni.utils;
2   
3   
4   import java.io.IOException;
5   import java.io.PrintWriter;
6   import java.io.StringWriter;
7   
8   /**
9    *	Clase de utilidad para el manejo de excepciones 
10   *	
11   *
12   */
13  public final class ExceptionUtils {
14  	
15  	/**
16  	 * Contructor
17  	 */
18  	private ExceptionUtils(){
19  		
20  	}
21  
22  	/**
23  	 * Convierte el stackTrace de una excepcion en una cadena de texto
24  	 * @param e Excepcion
25  	 * @return Cadena de texto con el stackTrace de la excepcion
26  	 */
27  	public static String stackTraceToString(Throwable e) {
28  		if(e==null){
29  			return null;
30  		}
31  		String retValue = null;
32  		StringWriter sw = null;
33  		PrintWriter pw = null;
34  		try {
35  			sw = new StringWriter();
36  			pw = new PrintWriter(sw);
37  			e.printStackTrace(pw);
38  			retValue = sw.toString();
39  		} finally {
40  			try {
41  				if(pw != null){
42  					pw.close();
43  				}
44  				if(sw != null){
45  					sw.close();
46  				}
47  			} catch (IOException ignore) {}
48  		}
49  		return retValue;
50  	}
51  }