import java.io.EOFException; import java.io.FileNotFoundException; import java.io.IOException; public class TryCatch { public static void main(String[] args) { bspAufgabenblatt(); //finale(); } public static void bspAufgabenblatt() { try { // Hier wird evtl. eine Exception geworfen: int exceptionArt = 1; switch (exceptionArt) { case 1: throw new EOFException(); // -> 1. i) case 2: throw new FileNotFoundException(); // -> 1. ii) case 3: // nichts // -> 1. iii) case 4: double rofl = 3/0; } } catch (EOFException e) { System.out.println("EOFException"); } catch (IOException e) { System.out.println("IOException"); } catch (Exception e) { System.out.println("Exception"); } System.out.println("ENDE"); } public static void finale() { System.out.println("START"); try { // Hier wird eine Exception (1 2, 3) geworfen oder ret (-1): int exceptionArt = 4; switch (exceptionArt) { case 1: throw new EOFException(); case 2: throw new FileNotFoundException(); case 3: throw new IllegalArgumentException(); case -1: return; // -> finally } } catch (EOFException e) { System.out.println("EOFException"); } catch (IOException e) { System.out.println("IOException"); throw new IllegalArgumentException(); // -> finally } // andere Exception? -> finally finally { System.out.println("FINALLY"); } System.out.println("ENDE"); } }