// (c) www.javapassion.com, Sang Shin ; mod.by DB (11/2008) public class FinallyDemo { public static void main( String args[] ) { for ( int i= 1; i <= 4; i++ ) { System.out.println( "main: avant try/catch" ); try { FinallyDemo.maMethode( i ); } catch ( Exception e ) { System.out.print( "main: Exception " ); System.out.println( e.getMessage() ); } System.out.println( "main: apres try/catch\n" ); } // for } // main() private static void maMethode( int n ) throws Exception { System.out.println( " maMethode: avant try/catch/finally" ); try { switch ( n ) { 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" ); } System.out.println( " maMethode: apres try/catch/finally" ); } // myMethod() } // FinallyDemo