Calling Time1 Method setTime with Invalid Values

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.

Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.