Convertir une exception à un String

Author:


{filelink=4378}


import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URLDecoder;
import java.util.Collection;
import java.util.Iterator;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.jar.JarFile;

public class StringStackTrace
{

  public static String getStringDeStackTrace(Throwable ex)
  {
      if (ex==null)
      {
          return "";
      }
      StringWriter str = new StringWriter();
      PrintWriter writer = new PrintWriter(str);
      try
      {
          ex.printStackTrace(writer);
          return str.getBuffer().toString();
      }
      finally
      {
          try
          {
              str.close();
              writer.close();
          }
          catch (IOException e)
          {
          }
      }
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *