```java public class ExampleTryCatch2 { public static void main(String[] args) { /* * 這個範例裡,仍然是蓄意製造兩個會拋出 Exception 的狀態。 * 在 test1 方法內有特別 catch 這個 Checked Exception, * * 但 test2 方法內沒有特別去處理這個 Checked Exception, * 而是把這個 Exception 向外拋出, * 呼叫方法的地方就必須 catch 住這個 Exception * * 所有的錯誤都有進行捕獲動作,讓這兩段的程式可以正常運作。 */ System.out.println("situation start"); test1(); //因為方法內有 try catch 住錯誤,所以程式不會掛掉 try { test2(); //直接 try catch 住錯誤,所以程式也不會掛掉 } catch (IOException e1) { e1.printStackTrace(); } System.out.println("situation fin"); } /* * 狀態一 * 使用 try catch 包覆住程式。 */ public static void test1() { //因為沒有指定正常的檔名跟路徑,所以這段必定會出現錯誤 File file = new File(""); try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } /* * 狀態二 * 不在方法內處理,選擇把 exception 往外丟 */ public static void test2() throws IOException { //因為沒有指定正常的檔名跟路徑,所以這段必定會出現錯誤 File file = new File(""); file.createNewFile(); } } ```