mercoledì 27 marzo 2013

Q11

Q11


An unchecked exception occurs in a method dosomething(). Should other code be added in the dosomething() method for it to compile and execute?
A.
The Exception must be caught
B.
The Exception must be declared to be thrown.
C.
The Exception must be caught or declared to be thrown.
D.
No other code needs to be added.


La risposta giusta è la D, infatti il compilatore non richiede di gestire le eccezioni unchecked, cioè quelle a runtime.

La risposta giusta è la C, infatti il compilatore non richiede di gestire le eccezioni unchecked (quelle a runtime) e quindi in fase di compilazione non abbiamo errori. Se l'eccezione occorre ce ne accorgiamo solo a runtime. La domanda richiede non solo di far compilare il codice ma anche di farlo girare (execute()) e quindi dobbiamo gestire questa eccezione ; la gestione può essere ottenuta come per tutte le eccezioni sia col trown che col try catch.
riferimento : eccezioni checked e unchecked

2 commenti:

  1. I think response is C, because it need compile and run. If it only were compile the reponse would be D.

    RispondiElimina