練習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("エラー!");
}
}