-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathOwnExceptionDemo.java
More file actions
69 lines (54 loc) · 1.31 KB
/
OwnExceptionDemo.java
File metadata and controls
69 lines (54 loc) · 1.31 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import java.util.Scanner;
class Emp
{
int empno;
String name;
Emp(int empno, String name)
{
this.empno = empno;
this.name = name;
}
@Override
public String toString() {
return "Emp [empno=" + empno + ", name=" + name + "]";
}
}
// System Exception
// Business Exception
// POJO (Plain Old Java Object) Class
// Step - 1 (Inherit the Exception Class)
// Now this class is become Checked Exception
class MinBalanceException extends Exception{ //extends Exception {
private int amount;
private int balance;
MinBalanceException(int amount,int balance){
this.amount = amount;
this.balance = balance;
}
@Override
public String toString(){
return "Your Balance is "+balance+" Low and U can't do any transaction... Amount is "+amount;
}
}
public class OwnExceptionDemo {
public static void main(String[] args) {
Emp ram =new Emp(1001,"Ram");
System.out.println(ram);
// TODO Auto-generated method stub
//main(null);
int balance = 0;
System.out.println("Enter the Amount to WithDraw");
int amount = new Scanner(System.in).nextInt();
try{
if(balance<=0){
//System.out.println("Balnce is Nil..");
throw new MinBalanceException(amount,balance);
}
// Calc Logic....
System.out.println("With Draw "+amount);
}
catch(MinBalanceException e){
System.out.println(e);
}
}
}