Laboratory Activity - Exception Handling
Laboratory Activity - Exception Handling
Problem:
Task 1: Basic Exception Handling
Steps:
1. Create a Java program that accepts two integers from the user and performs division.
2. Use a try-catch block to handle the following exceptions:
o ArithmeticException (e.g., division by zero).
o InputMismatchException (e.g., invalid input).
3. Display appropriate error messages for each exception.
1. Modify the program in Task 1 to include multiple catch blocks to handle other potential exceptions,
such as NumberFormatException.
2. Add input validation to ensure only integers are processed.
1. Create a method called performDivision that takes two integers as arguments and performs division.
2. Use the throws keyword in the method signature to declare that the method may throw
an ArithmeticException.
3. Call this method from the main method and handle the exception using a try-catch block.
Post-Lab Questions:
Submission Guidelines: