A Complete Example
- What can go wrong?
- File might not exist
- File might have data in wrong format
- Who can detect the faults?
- FileReader constructor will throw an exception when file does not exist
- Methods that process input need to throw exception if they find error in data format
- What exceptions can be thrown?
- FileNotFoundException can be thrown by FileReader constructor
- IOException can be thrown by close method of FileReader
- BadDataException, a custom checked exception class
- Who can remedy the faults that the exceptions report?
- Only the main method of DataSetTester program interacts with user
- Catches exceptions
- Prints appropriate error messages
- Gives user another chance to enter a correct file