- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThrowAndThrows.java
More file actions
Latest commit
39 lines (34 loc) · 940 Bytes
/
Copy pathThrowAndThrows.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
classNegativeRadiusExceptionextendsException{
@Override
publicStringtoString() {
return"Radius cannot be negative!";
}
@Override
publicStringgetMessage() {
return"Radius cannot be negative!";
}
}
publicclassThrowAndThrows {
publicstaticdoublearea(intr) throwsNegativeRadiusException{
if (r<0){
thrownewNegativeRadiusException();
}
doubleresult = Math.PI * r * r;
returnresult;
}
publicstaticintdivide(inta, intb) throwsArithmeticException{
intresult = a/b;
returnresult;
}
publicstaticvoidmain(String[] args) {
try{
doublear1 = divide(65,0);
System.out.println(ar1);
// double ar = area(-5);
// System.out.println(ar);
}
catch(Exceptione){
System.out.println("Exception");
}
}
}