Javaexamples-exception-checked
提供:Dev Guides
Javaの例-チェック済み例外の処理
問題の説明
チェック例外を処理する方法は?
溶液
この例は、catchブロックを使用してチェック済み例外を処理する方法を示しています。
public class Main {
public static void main (String args[]) {
try {
throw new Exception("throwing an exception");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
結果
上記のコードサンプルは、次の結果を生成します。
throwing an exception