×
例外処理
ゼロ除算エラーの発生を捕捉し、安全にプログラムを継続させる例外処理のコード例です。
public class ExceptionBasicExample {
    public static void main(String[] args) {
        try {
            int result = 10 / 0; // 実行時に ArithmeticException が発生
            System.out.println("結果: " + result);
        } catch (ArithmeticException e) {
            System.out.println("エラー発生: 0で割ることはできません。");
        }
        System.out.println("プログラムは安全に継続します。");
    }
}

もう少し詳しく