0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Java_throwで意図的に例外を投げよう

Posted at

paizaラーニングforTEAM Java入門編
レッスン10の#07

10-#07
// 例外処理 - throw

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello World");

        try {
            int number = 2;
            int answer = 100 / number;
            System.out.println(answer);
            throw new Exception("強制エラー");
        } catch (ArithmeticException e) {
            System.out.println("0では、割り算できません。");
            e.printStackTrace();
        // 例外ハンドラを追加
        } catch (Exception e) {
            System.out.println("例外が発生しました。");
            e.printStackTrace();
        } finally {
            System.out.println("Hello Java");
        }
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?