February 2014
Beginner
1248 pages
62h 25m
English
To illustrate that method setTime validates its arguments, line 23 calls method setTime with invalid arguments of 99 for the hour, minute and second. This statement is placed in a try block (lines 21–24) in case setTime throws an IllegalArgumentException, which it will do since the arguments are all invalid. When this occurs, the exception is caught at lines 25–28, and line 27 displays the exception’s error message by calling its getMessage method. Line 31 outputs the time again in both formats to confirm that setTime did not change the time when invalid arguments were supplied.
Read now
Unlock full access