You are on page 1of 1

Practice Questions for Exception Handling:

Question # 1:

Write a program that prompts the user to enter a length in feet and inches and outputs the equivalent
length in centimeters. If the user enters a negative number or a non - digit number, throw and handle an
exception and prompt the user to enter another set of numbers

Question # 2:

Write a program that prompts the user to enter time in 12 hour notation. The program then outputs the
time in 24 hour notation. Your program must contain three exception classes: invalidHr, invalidMin and
invalidSec. If the user enters an invalid value for hours, then the program should throw and catch an
invalidHr object. Do the same for minutes and seconds.

Question # 3:

Write a program that prompts the user to enter a person’s date of birth in numeric form such as 4-5-
1987. The program then outputs the date in the format: May 4, 1987. Your program should contain
atleast two exception classes: invalidDay and invalidMonth. If the user enters an invalid day value, the
program should throw and catch an invalidDay object. Do the same for invalid values of month and year.
Your program should also handle a leap year.

You might also like