public class UtilisationFinaly { public static void main(String[] argv) { new UtilisationFinaly().TesterException(); } public void TesterException() { Object objet = null; for (int i=0; i<5; i++) { try { objet = ExceptionSi(i); } catch (IllegalArgumentException e) { System.err.println("Exception: (" + e.getMessage() + ")."); return; } finally { System.err.println("Après la gestion de l'exception"); if (objet==null) System.exit(0); } } } public Object ExceptionSi(int type) throws IllegalArgumentException { if (type == 1) throw new IllegalArgumentException("Le nombre 1 est rejeté " + type); return new Object(); } } |
0