0% found this document useful (0 votes)
3K views2 pages

Java Practical No.23, 24 & 25 PDF

The program accepts a password from the user and compares it to a predefined password. If the entered password does not match, an AuthenticationFailure exception is thrown. The exception is caught and the error message "Handle Exception Authentication Failure" is printed.

Uploaded by

Meer Kukreja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3K views2 pages

Java Practical No.23, 24 & 25 PDF

The program accepts a password from the user and compares it to a predefined password. If the entered password does not match, an AuthenticationFailure exception is thrown. The exception is caught and the error message "Handle Exception Authentication Failure" is printed.

Uploaded by

Meer Kukreja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

23.

1) WRITE A PROGRAM TO ACCEPT A PASSWORD FROM THE USER AND THROW “AUTHENTICATION
FAILURE ” EXCEPTION IF THE PASSWORD IS INCORRECT.

PROGRAM:

import java.util.*;

class myException extends Exception

myException(String s)

super(s);

class pass

public static void main(String args[])

Scanner s=new Scanner(System.in);

String s1=new String ("Nesp");

String s2;

System.out.println("Enter the password:");

s2=s.next();

if(s1.equals(s2))

System.out.println("Login Successfully...!");

else

try

{
throw new myException("Authenification Failure");

catch(myException me)

System.out.println("Handle Exception"+me);

OUPUT:

You might also like