[program-java] Java: exception.printStackTrace....

  • From: "Corbett, James" <James.Corbett@xxxxxxxxxxxxx>
  • To: "'program-java@xxxxxxxxxxxxx'" <program-java@xxxxxxxxxxxxx>
  • Date: Fri, 15 Jul 2011 14:17:26 -0400

Hi:

I've sort of worked my away around the issue.

Here is a method that will return a string that I borowed and modified. All you 
need to do is pass in your exception and the string is returned for display 
purposes.

public static String getStackTrace(Throwable throwable) {
                StringWriter stringWriter = new StringWriter();
                PrintWriter printWriter = new PrintWriter(stringWriter, true);

                throwable.printStackTrace(printWriter);

                printWriter.flush();
                stringWriter.flush();

                return stringWriter.toString();
        }

James M. Corbett

Programmer / Analyst |
Canada Revenue Agency | Agence du revenue du Canada
875 Heron Rd.
Ottawa, On.
K1A0L5

James.Corbett@xxxxxxxxxxxxx
Telephone | Téléphone: (613) 941-1338
Facsimile | Télécopieur: (613) 941-2261

Government of Canada | Gouvernement du Canada


"Due to the highly confidential nature of my job, I'm not allowed to know what 
I'm doing."


Other related posts: