My code always expects the user to enter date in ‘MM/dd/yyyy’ format.
If the user enters in any other format, it should throw an exception.
But in the following case, the code returns 12 July 1994 as response instead of throwing an error.
public static void main(String[] args) {
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH);
try {
System.out.println(format.parse("19/12/1993"));
}
catch(Exception e) {
System.out.println("Exception");
}
}
I’m expecting the code to throw an exception