-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThrowAndThrows.java
More file actions
39 lines (34 loc) · 940 Bytes
/
ThrowAndThrows.java
File metadata and controls
39 lines (34 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class NegativeRadiusException extends Exception{
@Override
public String toString() {
return "Radius cannot be negative!";
}
@Override
public String getMessage() {
return "Radius cannot be negative!";
}
}
public class ThrowAndThrows {
public static double area(int r) throws NegativeRadiusException{
if (r<0){
throw new NegativeRadiusException();
}
double result = Math.PI * r * r;
return result;
}
public static int divide(int a, int b) throws ArithmeticException{
int result = a/b;
return result;
}
public static void main(String[] args) {
try{
double ar1 = divide(65,0);
System.out.println(ar1);
// double ar = area(-5);
// System.out.println(ar);
}
catch(Exception e){
System.out.println("Exception");
}
}
}