Question:
Comment afficher la trace d'une exception en java ?
igor.aigrishka
2006-06-12 02:32:32 UTC
Comment afficher la trace d'une exception en java ?
Deux réponses:
Nicolas
2006-06-14 10:13:24 UTC
le projet apache Commons Lang http://jakarta.apache.org/commons/lang/ contient une classe ExceptionUtils avec une methode statique getStackTrace(Throwable) qui renvoi une chaine de caratère (String) qu'on peut utiliser ou afficher ou bon nous semble. Elle contient ce qui serai apparu dans la console en faisant un e.printStackTrace().

le source ce cette méthode est le suivant :

(throwable est l'exception a afficher)



StringWriter sw = new StringWriter();

PrintWriter pw = new PrintWriter(sw, true);

throwable.printStackTrace(pw);

String resultat= sw.getBuffer().toString();
gulbuddin.hekmatyar
2006-06-12 05:43:05 UTC
vous pouvez utiliser la methode printStackTrace() pour tous les objets Throwable.


Ce contenu a été initialement publié sur Y! Answers, un site Web de questions-réponses qui a fermé ses portes en 2021.
Loading...