import java.io.PrintWriter; import java.io.StringWriter; public class ExempleException { public static void ExempleException(String args[]) { try { throw new Exception("G�n�rer une exception"); } catch (Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); System.out.println(sw.toString().toUpperCase()); } } }
A voir sur le même Sujet
-
Gestion des Exception: Ajouter une exécution dans la section finaly
{filelink=4358} class MonException extends Exception { } public class ExempleFinaly { static int x = 0; public static void main(String[] args) { while (true) { …
-
Gestion des Exceptions: Comment afficher les information de stack Trace avec StackTraceElement
{filelink=4384} public class StackTrace { public static boolean displayStackTraceInformation(Throwable ex) { ex.printStackTrace(); StackTraceElement[] stackElements = ex.getStackTrace(); System.out.println(“Le ” + stackElements.length + ” element” + ((stackElements.length …
-
Classe ‘Formatter’: Exemple de ‘Formatter.ioException()’ pour la gestion des exceptions
{filelink=5780} import java.io.FileOutputStream; import java.util.Formatter; public class ExceptionFormatter { public static void main(String[] argv) throws Exception { Formatter fmtCon = new Formatter(System.out); Formatter fmtFile; fmtFile …
-
Exemple des Methodes de la Classe Exception.
{filelink=4356} public class MethodesException { public static void main(String[] args) { try { throw new Exception(“Mes Exceptions”); } catch (Exception e) { System.err.println(“M�thode getMessage():” + …
-
Comment gérer les Exceptions enchaînés en JDBC
{filelink=893} import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class JDBCException { static Connection conn; public static void main(String[] args) { String …
-
Une collection de méthodes utilitaires pour manipuler les exceptions
{filelink=4385} import java.io.*; public final class StringDansException { public static String obtenirLeStringDeStackTrace(Throwable t) { if (t != null) { StringWriter sw = new StringWriter(); PrintWriter …
-
Créer une représentation String des Exceptions
{filelink=4373} import java.io.PrintWriter; import java.io.StringWriter; /** * Utilitaire String * Créer une representation String de l’exception. */ public class ReprésentationString { public static String stringifierException(Throwable …
-
Moteur des scripts: Exemple de gestion des exceptions
{filelink=939} import javax.script.Bindings; import javax.script.ScriptContext; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class ExceptionScript { public static void main(String[] args) { ScriptEngineManager manager = new …
-
Comment Transformer en String le resultat de printStackTrace
{filelink=4369} import java.io.ByteArrayOutputStream; import java.io.PrintWriter; public class Exemple { public static final String stackTrace(Throwable e) { String excep = null; try { ByteArrayOutputStream ostr = …
-
Exemple de Gestion d’exception XMLStreamException “”
{filelink=986} import java.io.FileInputStream; import javax.xml.namespace.QName; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.events.XMLEvent; class StaxCursorTest { public static void main(String[] args) throws Exception { String …