January 2014
Intermediate to advanced
736 pages
70h 43m
English
To illustrate that method setTime validates its arguments, line 29 calls method setTime with invalid arguments of 99 for the hour, minute and second. This statement is placed in a try block (lines 27–30) 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 31–34, and line 33 displays the exception’s error message by calling its getMessage method. Lines 37–41 output 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