Throws vs throws

 package com.company;

class negativeRadiusException extends Exception{
@Override
public String toString() {
return "Negative radius not allow";
}
@Override
public String getMessage() {
return "Area is not negative";
}
}
public class CWH_84_throwVsThrow {
public static double area(int r) throws negativeRadiusException{
if(r<0){
throw new negativeRadiusException();
}
double ar= Math.PI*r*r;
return ar;
// System.out.println(ar);
}
public static int divide(int a,int b) throws ArithmeticException{
int c= a/b;
return c;
}
public static void main(String[] args) {
try {
// double result = divide(54, 0);
// System.out.println(result);
double a= area(-9);
System.out.println(a);
}
catch(Exception e){
System.out.println("Exception");
System.out.println(e.getMessage());
}
}
}

Comments