LoginSignup
0
0

More than 5 years have passed since last update.

JAVA 15.10練習問題(P597)

Last updated at Posted at 2015-11-17

練習15-2 解答


public class Test08 {
    public static void main(String[] args) {

        try {
            String s = null;
            System.out.println(s.length());

        } catch (NullPointerException e) {
            System.out.println("NullPointerException例外をcatchしました");
            System.out.println("――スタックトレース(ここから)――");
            e.printStackTrace();
            System.out.println("――スタックトレース(ここから)――");
        }
    }

}

練習問題 15-3 解答

public class Test09 {
    public static void main(String[] args) {
        try {
            int i = Integer.parseInt("三");
        } catch (NumberFormatException e) {
            System.out.println("例外NumberFormatExceptionをcatchしました");

        }
    }
}

練習問題15-4 解答

import java.io.IOException;

public class Test10 {
    public static void main(String[] args) throws IOException {
        System.out.println("プログラムが起動");
        throw new IOException("エラー!");
    }
}
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