1

I have the following try and catch snippet.

try{
    ...

} catch(Exception e){
    System.out.print("error");
    e.printStackTrace();
}

error is displayed in admin console but I can't see the e.printStackTrace();

JR Galia
  • 17,229
  • 19
  • 92
  • 144

2 Answers2

4

printStackTrace outputs to standard error, and System.out outputs to standard output. You can redirect the stack trace to standard output:

e.printStackTrace(new PrintWriter(System.out));

Then it will appear in the admin console.

tbodt
  • 16,609
  • 6
  • 58
  • 83
0

Another approach is to convert the stack trace to a string and then you can log it or print it the same as the string you're already printing.

Here's how to get the stack track as a string: How to store printStackTrace into a string

Community
  • 1
  • 1
Michael Osofsky
  • 11,429
  • 16
  • 68
  • 113