Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaPack;
- public class ThrowException {
- public static double divide(double x, double y) {
- if (y==0) {
- throw new ArithmeticException("Divider cannot be zero!");
- }
- return x/y;
- }
- public static void main(String[] args) {
- double d;
- try {
- d = divide(8.4,0);
- System.out.println("Result: " +d);
- }
- catch(ArithmeticException e) {
- System.out.println(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement