... executed in throwException");
32         }
33
34         // code here would not be reached; would cause compilation errors
35      }
36
37      // demonstrate finally when no exception occurs
38      public static void doesNotThrowException() {
39         try { // try block does not throw an exception
40            System.out.println("Method doesNotThrowException");
41         }
42         catch (Exception exception) { // does not execute
43            System.err.println(exception);
44         }
45         finally { // executes regardless of what occurs in try…catch
46            System.err.println("Finally executed in doesNotThrowException");
47         }
48
49         System.out.println("End of method doesNotThrowException");
50      }
51   }
Method throwException Exception handled in method throwException Finally executed in throwException Exception handled in main Method ...

Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.