First page Back Continue Last page Graphics
13.4 Simple Exception-Handling Example: Divide by Zero
Upcoming example
- Handle divide-by-zero errors
- Define new exception class
- DivideByZeroException
- Inherit from exception
- In division function
- Test denominator
- If zero, throw exception (throw object)
- In try block
- Attempt to divide
- Have enclosing catch block
- Catch DivideByZeroException objects