1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| public Date lireDate()
throws DateTropLongueException,
DateTropVieilleException,
DateFuturException {
String string = maFonctionLireDate();
if (string.length()>10)
return new DateTropLongueException();
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
date = simpleDateFormat.parse(string);
Date debut = simpleDateFormat.parse("01/01/1950");
Date fin = simpleDateFormat.parse("01/01/2050");
if (date.before(debut))
return new DateTropVieilleException();
if (date.after(fin))
return new DateFuturException();
return date;
}
public void utiliserDate(){
Date date;
try{
date = lireDate();
}catch(DateTropLongueException e){
System.err.println("Fichier corrompu");
return;
}catch(DateTropVieilleException e){
date = new SimpleDateFormat("dd/MM/yyyy").parse("01/01/1950");
}catch(DateFuturException e){
date = new SimpleDateFormat("dd/MM/yyyy").parse("01/01/2050");
}
traiterDate(date);
} |
Partager