-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemoException
48 lines (47 loc) · 1.15 KB
/
DemoException
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
import java.util.Scanner;
class UsernameException extends Exception
{
public UsernameException(String msg) {
super(msg);
}
}
class PasswordException extends Exception
{
public PasswordException(String msg) {
super(msg);
}
}
class DemoExcp
{
public static void main(String args[])
{
String name="bibin";
String pass="bibin2002";
Scanner s= new Scanner(System.in);
System.out.print("Enter username :: ");
String user=s.nextLine();
System.out.print("Enter password :: ");
String pwd=s.nextLine();
try
{
if(!user.equals(name))
throw new UsernameException("Username incorrect");
else if(!pwd.equals(pass))
throw new PasswordException("Password incorrect");
else
System.out.println("Login Successful !!!");
}
catch(UsernameException u)
{
u.printStackTrace();
}
catch(PasswordException p)
{
p.printStackTrace();
}
}
}
output
Enter username :: revathi
Enter password :: revathi2002
Login Successful !!!