1102自主学習
This commit is contained in:
@@ -11,13 +11,13 @@ public class Question16_4 {
|
||||
int num2 = ageCheck(-5);
|
||||
System.out.println("年齢は" + num2 + "です");
|
||||
}catch(testException e) {
|
||||
System.out.println(e.getMessage()+ "は不正な年齢です");
|
||||
System.out.println(e.getAge()+ "は不正な年齢です");
|
||||
}
|
||||
}
|
||||
|
||||
public static int ageCheck(int num) throws testException {
|
||||
if(num < 0) {
|
||||
throw new testException("num");
|
||||
throw new testException(num);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
|
||||
public class testException extends Exception {
|
||||
public testException(String message) {
|
||||
super(message);
|
||||
private final int age;
|
||||
|
||||
public testException(int num) {
|
||||
this.age = num;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user