Commit fc249677 authored by Trisha Gee's avatar Trisha Gee
Browse files

[Ch11] Code Magnets exercise

parent 38ba0eb3
Loading
Loading
Loading
Loading
+29 −0
Changes for src/main/java/ch11/ExTestDrive.java: 29 added lines, 0 removed lines.
Original line number Diff line number Diff line
package ch11;

class MyEx extends Exception { }

public class ExTestDrive {
  public static void main(String[] args) {
    String test = args[0];
    try {
      System.out.print("t");
      doRisky(test);
      System.out.print("o");
    } catch (MyEx e) {
      System.out.print("a");
    } finally {
      System.out.print("w");
    }
    System.out.println("s");
  }

  static void doRisky(String t) throws MyEx {
    System.out.print("h");

    if ("yes".equals(t)) {
      throw new MyEx();
    }

    System.out.print("r");
  }
}