Why can't I catch an exception?
I've been converting between dates and strings with the form "03/18/09". The code splits the string at the /'s, converts to integers, and sticks it in an instance of Calendar. There are a few different ways for that to go wrong: non-numbers, not enough numbers, and not a valid date. So I've been using try/catch blocks so that parseInt() and Calendar.set() can throw whatever they want, and I just throw my own NumberFormatException if I don't have enough numbers. The exception handling is to refocus on the date field with the text selected, so the user can try again. And that works fine with non-numbers or too few numbers.
But I get runtime errors vomiting on the screen when I try an invalid date, even from a try/catch block. That part of the code (not including diagnostic System.out.println()s) looks something like this.
Code:
try {
DateString.StringToCal(ds, Database.date);
}
catch (Exception ex) {
dateText.requestFocus();
}
I thought that would catch any exception that can be thrown. What's up with that?