質問編集履歴
2
変更
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
```Java
|
|
2
2
|
class InvalidIdException extends Exception { }
|
|
3
3
|
class MissingNameException extends Exception { }
|
|
4
|
-
class
|
|
4
|
+
class Patron {
|
|
5
5
|
private int id;
|
|
6
6
|
private String name;
|
|
7
|
-
public
|
|
7
|
+
public Patron(int id, String name) throws Exception {
|
|
8
8
|
if (id < 1) {
|
|
9
9
|
throw new InvalidIdException();
|
|
10
10
|
} else if (name == null) {
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
return " [ " + id + " : " + name + " ] ";
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
public class
|
|
20
|
+
public class Owner {
|
|
21
21
|
//public static void main(String[] args) { // 1.add throws declaration 2.surround with try/catch
|
|
22
22
|
public static void main(String[] args) throws Exception {
|
|
23
|
-
|
|
23
|
+
Patron p1 = new Patron(101, "Beethoven");
|
|
24
|
-
|
|
24
|
+
Patron p2 = new Patron(102, "Mozart");
|
|
25
|
-
System.out.print(
|
|
25
|
+
System.out.print(p1);
|
|
26
|
-
System.out.print(
|
|
26
|
+
System.out.print(p2);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
```
|
1
誤字
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
```
|
|
30
|
-
ある問題集のスクリプトですが、throws を書いているのに catch がないのですが、エラーなく実行で
|
|
30
|
+
ある問題集のスクリプトですが、throws を書いているのに catch がないのですが、エラーなく実行できてしまいます。
|
|
31
31
|
|
|
32
32
|
throw して throws して、それを catch するものがなくてもエラーがないというところが、どう考えたら良いものかわかりません。
|
|
33
33
|
必ずしも catch は必要ではないということなのでしょうか?
|