Method setTime and Throwing Exceptions

Method setTime (lines 12–25) is a public method that declares three int parameters and uses them to set the time. Lines 15–16 test each argument to determine whether the value is outside the proper range. The hour value must be greater than or equal to 0 and less than 24, because universal-time format represents hours as integers from 0 to 23 (e.g., 1 PM is hour 13 and 11 PM is hour 23; midnight is hour 0 and noon is hour 12). Similarly, both minute and second values must be greater than or equal to 0 and less than 60. For values outside these ranges, setTime throws an exception of type IllegalArgumentException (lines 18–19), which notifies the client code that an invalid argument was passed to the method. ...

Get Java™ How To Program (Early Objects), Tenth 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.