-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.java
More file actions
29 lines (24 loc) · 777 Bytes
/
Account.java
File metadata and controls
29 lines (24 loc) · 777 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
package ExceptionHandling;
import java.io.IOException;
import ExceptionHandling.InsufficientFundsException;
import ExceptionHandling.AccountException;
public class Account {
private float balance;
// throws: provides info method might throw IOException
// Checked exceptions must be handled
public void deposit(float value) throws IOException {
// Unchecked exception
if (value < 0) {
throw new IllegalArgumentException();
}
// Checked Exception
if (value == 0) {
throw new IOException();
}
}
public void withdraw(float value) throws AccountException {
if (value > balance) {
throw new AccountException(new InsufficientFundsException());
}
}
}