Javaexamples-exception-checked

提供:Dev Guides
2020年6月22日 (月) 17:29時点におけるMaintenance script (トーク | 投稿記録)による版 (Imported from text file)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

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