Im Struggling to implement a try catch that works by making a user input a string that is compatible with an java.sql.Date object using the scanner. If you guys have any idea how to write a try catch for the format "yyyy-mm-dd" that would be really useful. Ill toss the relevant code below. Thank you!
This is the try catch that I attempted.
try{
System.out.print("Enter release date : yyyy-mm-dd ");
String d = keyboard.nextLine();
releaseDate =Input.parse(java.sql.Date.valueOf(d));
}
catch(ParseException pe){
pe.printStackTrace();
// log the exception
throw new RuntimeException(pe);
System.out.print("Enter release date : yyyy-mm-dd ");
String d = keyboard.nextLine();
releaseDate = java.sql.Date.valueOf(d);
This is the code that works without exception checking
Please login or Register to submit your answer