Gestion des Exceptions: Comment mettre un printStackTrace() dans un String

Author:


Download

 
import java.io.PrintWriter;
import java.io.StringWriter;
 
public class ExempleException {
  public static void ExempleException(String args[]) {
    try {
      throw new Exception("G�n�rer une exception");
    } catch (Exception e) {
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      e.printStackTrace(pw);
      System.out.println(sw.toString().toUpperCase());
    }
  }
}