上級 › unreported exception must be caught の原因と直し方 › パターン3
unreported exception must be caught の原因と直し方
検査例外と非検査例外の境界。
1 import java.io.IOException; 2 3 public class Main { 4 public static void main(String[] args) { 5 try { 6 int[] a = new int[1]; 7 System.out.println(a[5]); 8 } catch (______________________________ e) { ^ 9 System.out.println("caught"); 10 } 11 } 12 }
Main.java:8: error: exception IOException is never thrown in body of corresponding try statement
空欄を埋めてビルドを通す
try内で発生しない検査例外は捕まえられません。非検査例外なら書けますが、型が合わなければ捕捉されません。
次の問題