/** * * un exemple des blocs: try-catch-finally * * @author Mughal & Rasmussen * @author Mohamed Lokbani pour l'emballage! * * @version 1.1 */ public class exo3 { static void f() throws InterruptedException { throw new InterruptedException("la solution est ..."); } public static void main(String args[]) { try { f(); } catch (InterruptedException e) { System.out.println("1"); throw new RuntimeException(); } catch (RuntimeException e) { System.out.println("2"); return; } catch (Exception e) { System.out.println("3"); } finally { System.out.println("4"); } System.out.println("5"); } } /* 1 4 Exception in thread "main" java.lang.RuntimeException at exo3.main(exo3.java:25) dans le try, appel de la méthode f() dans la méthode f() on lève InterruptedException elle sera capturée dans le méthode par le catch approprié. dans ce catch la, il y a une exception du type RuntimeException elle doit être capturée par un bloc d'un niveau supérieur or ici on est dans le main, donc sortie du programme. avant de sortir, le bloc finally est exécuté, du coup affichage de 4. puis le message comme quoi une exception a été levée à la ligne 15 mais n'a pas été capturée. */