HandleTimeException Program
Description
This program uses the programmer-defined exception classes to handle time exceptions.Associated Concepts:
Exception Handling
Algorithm:
main method:
Input an integer: hours, for a time in hour.
Input an integer: minutes, for a time in minute.
Input an integer: seconds, for a time in second.
The program prints the time in HH:MM:SS format if no exception occurred.
If the user entered an invalid integer, the try block terminates
immediately, and the program execution jumps to the matching
catch block to handle the InputMismatchException.
If the user input is less than 0 or greater 12, the program throws an InvalidHourException which is a programmer-defined exception type.
If the user input is less than 0 or greater 12, the program throws an InvalidHourException which is a programmer-defined exception type.
Input an integer: minutes, for a time in minute.
If the user entered an invalid integer, the try block terminates
immediately, and the program execution jumps to the matching
catch block to handle the InputMismatchException.
If the user input is less than 0 or greater 59, the program throws an InvalidMinuteException which is a programmer-defined exception type.
If the user input is less than 0 or greater 59, the program throws an InvalidMinuteException which is a programmer-defined exception type.
Input an integer: seconds, for a time in second.
If the user entered an invalid integer, the try block terminates
immediately, and the program execution jumps to the matching
catch block to handle the InputMismatchException.
If the user input is less than 0 or greater 59, the program throws an InvalidSecondException which is a programmer-defined exception type.
If the user input is less than 0 or greater 59, the program throws an InvalidSecondException which is a programmer-defined exception type.
The program prints the time in HH:MM:SS format if no exception occurred.