// (c) www.javapassion.com, Sang Shin ; mod.by DB (04/2012) public class FinallyDemo { public static void main( final String pArgs[] ) { for ( int vI= 1; vI <= 4; vI++ ) { System.out.println( "main: avant try/catch" ); try { FinallyDemo.maMethode( vI ); } catch ( Exception e ) { System.out.println( "main: Exception message = " + e.getMessage() ); System.out.println( "main: toString = " + e.toString() ); } // try/catch System.out.println( "main: apres try/catch\n" ); } // for } // main() private static void maMethode( final int pN ) throws Exception { System.out.println( " maMethode: avant try/catch/finally" ); try { switch ( pN ) { case 1 : System.out.println( " maMethode: case 1" ); return; // no break case 3 : System.out.println( " maMethode: case 3" ); throw new RuntimeException( "3!" ); // no break case 4 : System.out.println( " maMethode: case 4" ); throw new Exception( "4!" ); // no break case 2 : System.out.println( " maMethode: case 2" ); // no break } // switch } catch ( RuntimeException e ) { System.out.print( " maMethode: RuntimeException " ); System.out.println( e.getMessage() ); } finally { System.out.println( " maMethode: bloc finally" ); } // try/catch/finally System.out.println( " maMethode: apres try/catch/finally" ); } // myMethod() } // FinallyDemo