This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Hello, I think I should be getting an exception here but i'm not. I have: SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy", user.getLocale()); When I try to parse an *invalid* date I expected an exception to be thrown: sdf.parse("99/99/9999"); I am NOT getting an exception and Java returns a java.util.Date object with the toString value: Thu Jun 07 00:00:00 CDT 10007 Shouldn't the parse() method have thrown an exception? How do I get it to?
According to the API the only exception thrown by parse is a NullPointerException, and your invalid date certainly was not null. That's true for parse(String, ParsePosition) - but not parse(String) which is defined in DateFormat and not overridden. Michael, could you show the code you're using to parse this?
Michael Dunn's tip worked for me, thanks Michael. When I set lienient to false, the parsing would not allow dates like 99/99/9999 or 4/40/2004. If lienient is not working for you, search through your code for "new SimpleDateFormat" and ".getInstance". The first time I tried setting lienient to false did not work because I missed a place in my code where I create a DateFormat object with ".getInstance"