fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10.  
  11. private static String convertStackTrace(Throwable throwable) {
  12. try (StringWriter sw = new StringWriter();
  13. PrintWriter pw = new PrintWriter(sw)) {
  14. throwable.printStackTrace(pw);
  15. return sw.toString();
  16. } catch (IOException ioe) {
  17. // this can never really happen..... as a result,
  18. // just convert to a Runtime exception
  19. throw new IllegalStateException(ioe);
  20. }
  21. }
  22.  
  23. public static void main (String[] args) throws java.lang.Exception
  24. {
  25. System.out.println(convertStackTrace(new IllegalStateException("boo")));
  26. }
  27. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
java.lang.IllegalStateException: boo
	at Ideone.main(Main.java:25)