COMP2247 - Algorithms and Data Structures

Syllabus Software Installation Assignments Tests
Lectures and Labs
**Back to Full Menu**

Exception Handling Practice1.java QuadraticEquation.java YouthLeague.java HandleTimeException Program
InvalidHourException.java
InvalidMinuteException.java
InvalidSecondException.java
HandleTimeException.java
HardwareStore Programs



HardwareStoreWithException Program


Description

This program uses the exception handling techniques to handle possible exceptions in the HardwareStore project.

Associated Concepts:

Exception Handling

Algorithm:

main method:

Use try and catch mechanism to handle file IO exceptions instead of using the throw clause in the main() method signature.

Handle the InputMismatchException for the user input of case number.

Handle exception in each case in the event that the array was not populated correctly.

populateArray() method definition:

If the data file has more data items than the array size, the try block terminates immediately, and the program execution jumps to the matching catch block to handle the IndexOutOfBoundsException.

If the data file has missing data item, the try block terminates immediately, and the program execution jumps to the matching catch block to handle the NoSuchElementException.

The catch block with the superclass Exception type handles any unexpected exceptions.

Source Code



Sample Run



Video