Write a class InvalidCNICException that extends Exception class.
The class should have following details implemented
– A message property.
– override following method that returns message
String toString()
– Two constructors
1. With no parameter
2. With String parameter
Take user input for CNIC. The CNIC is considered valid if
1. The length of CNIC is 15(including -)
2. if the hyphen(-) is present at position 6 and 14.
Generate (throw) InvalidCNICException when an invalid CNIC has been entered by the user. Handle this exception by giving user a responsive message saying "The CNIC you entered is not valid
Comments
Leave a comment