Java Program to Throw an Exception if two strings are not equal

Write a Java program to throw a user-defined exception "String mismatch" exception, if two strings are not equal (ignore the case)..



Source Code
import java.util.Scanner;

class StringMismatchException extends Exception {
	
	public StringMismatchException(String str) {
		
		System.out.println(str);
	}
}
public class StringExcDemo {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		System.out.print("Enter the string :: ");
		String input = scan.nextLine();
		
		try {
			if(input.equalsIgnoreCase("Hello"))
				System.out.println("String matched !!!");
			else
				throw new StringMismatchException("String not matched ???");
		}
		catch (StringMismatchException s) {
			System.out.println(s);
		}
	}

}
Output
Enter the string :: Hello
Strings matched !!!

Enter the string :: HELLO
String matched !!!

Enter the string :: Hi
Strings mismatch ???
exception.StringMismatchException