Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaPack;
- public class ThrowableMethods {
- public static double divide(double x, double y) {
- if (y==0) {
- throw new ArithmeticException("Arithmetic Exception occurred");
- }
- return x/y;
- }
- public static void main(String[] args) {
- double d;
- try {
- d = divide(5.6,0);
- }
- catch(ArithmeticException e) {
- //System.out.println("Divider cannot be equal to zero");
- //useful methods
- System.out.println(e.getMessage()); //print above from divide() method
- System.out.println(e.toString());
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement