giovedì 28 marzo 2013

Q34


Which three are bad practices?
A.
Checking for ArrayIndexOutOfBoundsException when iterating through an array to determine when all elements have been visited
B.
Checking for Error and if necessary, restarting the program to ensure that users are unaware problems
C.
Checking for FileNotFoundException to inform a user that a filename entered is not valid
D.
Checking for ArrayIndexOutOfBoundsExcepcion and ensuring that the program can recover if one occur
E.
Checking for an IOException and ensuring that the program can recover if one occurs

 Risposta :
A : Questo è abbastanza stupido da fare, scorrere un array fino a far scatenare un'eccezione non è una buona pratica. Meglio ragionare sull'indice ed evitare l'eccezione.
B : Non ha alcun senso far riavviare un programma se si ottiene un errore!
E
D : Questa pratica è da evitare per gli stessi motivi del punto A. In generale è sbagliato basarsi sulla cattura di un'eccezione evitabile come la ArrayIndexOutOfBoundsException  . Invece è giusto prevedere di avere delle eccezioni che non dipendono da come abbiamo scritto il programma, come le FileNotFoundException e IOException  .

2 commenti:

  1. I think the response is A,B,D. Because checking for FileNotFoundException and IOException exceptions are good practices.

    RispondiElimina
  2. you're absolutely right.
    I was wrong to write the letter but the comment was right!

    thank you very much

    RispondiElimina