-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path9_ExceptionRealTimeEx.java
51 lines (34 loc) · 1.08 KB
/
9_ExceptionRealTimeEx.java
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
import java.io.*;
class InvalidCredentialsException extends RuntimeException{
InvalidCredentialsException(String msg) {
super(msg);
}
}
class Main {
static String userName1 = "dhirajgadekar";
static String password1 = "dhiraj@123";
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter UserName : ");
String userName2 = br.readLine();
System.out.print("Enter Password : ");
String password2 = br.readLine();
boolean flag = true;
while(flag) {
if(!(userName1.equals(userName2) && password1.equals(password2))) {
try {
throw new InvalidCredentialsException("Invalid username or password");
} catch(InvalidCredentialsException ivc) {
System.out.println(ivc.getMessage());
System.out.print("Enter UserName : ");
userName2 = br.readLine();
System.out.print("Enter Password : ");
password2 = br.readLine();
}
} else {
System.out.println("Login Successful");
flag = false;
}
}
}
}