Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

parse method of SimpleDateFormat is not throwing exception

 
Abdul Mohsin
Ranch Hand
Posts: 111
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Parse method of SimpleDateFormat is not giving any exception when wrong month say(20) passed to it.
I am not able to find any way get the exception if wrong month is passed to it.


SimpleDateFormat format = new SimpleDateFormat( "MM_dd_yyyy_HH_mm_ss" );
ParsePosition pos= new ParsePosition(0);
format.parse("20_12_2007_05_23_13",pos); // month is passed as 20
System.out.println("After parsing error index:"+pos.getErrorIndex());
System.out.println(" Parse index:"+pos.getIndex());


This code compiles and run perfectly and not throw any exception inspire of passing month as 20.

Please help..

Regards,

Abdul Mohsin
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try turning off lenient processing by calling
 
Abdul Mohsin
Ranch Hand
Posts: 111
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot , it works.

Regards,

Abdul Mohsin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic