Use your exception handling skills to build a division calculator that gracefully handles errors — including division by zero — using try/catch and a custom exception.
YOUR TASK
Create a program that:
Creates a custom exception: DivisionByZeroException
Writes a divide(int a, int b) method that throws it when b == 0
Calls divide(10, 2) and prints the result
Calls divide(5, 0) inside a try/catch and prints the error message
Need a hint?
class DivisionByZeroException extends Exception { ... }
Pass a message to the parent: super("Cannot divide by zero");
In the catch block: System.out.println("Error: " + e.getMessage());
Expected Output:
Result: 5
Error: Cannot divide by zero
Code Editor Ready
Output
Console
Console initialized...
Ready for Project 3: Safe Division Calculator
> Remember: custom exceptions extend the Exception class
> Use try/catch to handle the DivisionByZeroException!