忍者ブログ

学習用

2025
04,28

«[PR]»

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

2020
07,15
// 例外処理とはプログラム実行中に予期しない結果が発生したときに
適切に処理をしていく方法のこと
class MyException extends Exception {
  public MyException(String s) {
    super(s);
  }
}
public class MyApp {
  public static void div(int a, int b) {
    try {
      if (b < 0) {
        throw new MyException("not minus!");
      }
      System.out.println(a / b);
    } catch (ArithmeticException e) {
      System.err.println(e.getMessage());
    } catch (MyException e) {
      System.err.println(e.getMessage());
    } finally {
      System.out.println(" -- end -- ");
    }
  }
  public static void main(String[] args) {
    div(3, 0);
    div(5, -2);
  }
}
PR
Post your Comment
Name:
Title:
Mail:
URL:
Color:
Comment:
pass: emoji:Vodafone絵文字 i-mode絵文字 Ezweb絵文字

[39] [38] [37] [36] [35] [34] [33] [32] [30] [29] [28]


« ラッパークラス_1: HOME : 列挙型_enum_1 »
プロフィール
HN:
No Name Ninja
性別:
非公開
カテゴリー
最新記事
P R

Powered by Ninja.blog * TemplateDesign by TMP
忍者ブログ[PR]