ParseException直接捕获

时间:2017-07-19 10:54:32

标签: java try-catch simpledateformat parseexception

我的SimpleDateFormat不断投掷ParseException。我无法让它真正进入try块,它只是直接进入我的捕获。知道我的代码有什么问题吗?

public static String getEventDate() throws ParseException {
    System.out.println("When is the date of your event? (dd/MM/yyyy)");
    String date = in.nextLine();
    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    Date eventDate = null;
    try {
        eventDate = dateFormat.parse(date);
    } catch (ParseException e) {
        System.out.println("Error in date format");
    }

    String finalDate = dateFormat.format(eventDate);
    return finalDate;

}




public static void main(String[] args) throws ParseException {
    Event event = getEventInfo();
    System.out.println(event);

}
public static Event getEventInfo() throws ParseException {
    String eventType = getEventType();
    String eventDate = getEventDate();
    Event event = new Event(eventType, eventDate);
    return event;
}

0 个答案:

没有答案