-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomexception.java
More file actions
40 lines (33 loc) · 864 Bytes
/
customexception.java
File metadata and controls
40 lines (33 loc) · 864 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
40
package exceptionhandling;
class amount{
private String curr;
private int amt;
//constructor
public amount(String curr, int amt) {
super();
this.curr = curr;
this.amt = amt;
}
public void add(amount that)throws CurrenciesDonotMatch{
if(!this.curr.equals(that.curr)) {
throw new CurrenciesDonotMatch("Currency donot match "+this.curr+" & "+that.curr);
}
this.amt+=that.amt;
}
public String toString() {
return amt+" "+curr;
}
}
class CurrenciesDonotMatch extends Exception {
CurrenciesDonotMatch(String msg){
super(msg);
}
}
public class customexception {
public static void main(String[] a) throws CurrenciesDonotMatch {
amount a1=new amount("EUR",10);
amount a2=new amount("EUR",20);
a1.add(a2);
System.out.println(a1);
}
}