0% found this document useful (0 votes)
117 views

Exception Handling Questions

The document contains 3 practice questions about exception handling in programming. Question 1 prompts the user to enter a length in feet and inches and converts it to centimeters, throwing an exception if non-numeric values are entered. Question 2 prompts for time in 12-hour format and converts to 24-hour, throwing specific exception classes for invalid hours, minutes, or seconds. Question 3 prompts for a date of birth and converts it to a word format, throwing exception classes for invalid day or month values.

Uploaded by

Farrukh Abbas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views

Exception Handling Questions

The document contains 3 practice questions about exception handling in programming. Question 1 prompts the user to enter a length in feet and inches and converts it to centimeters, throwing an exception if non-numeric values are entered. Question 2 prompts for time in 12-hour format and converts to 24-hour, throwing specific exception classes for invalid hours, minutes, or seconds. Question 3 prompts for a date of birth and converts it to a word format, throwing exception classes for invalid day or month values.

Uploaded by

Farrukh Abbas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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