When i use this below code, compilation error happens.
try {
throw new Exception("Exceptionist");
System.out.println("another line"); //compilation error
}catch (Exception e) {
System.out.println("Exception:" + e.getMessage());
}
The reason for compilation error is that we cannot write code after throwing an exception. But when i try something like this
try {
if (true)
throw new Exception("Exceptionist");
System.out.println("another line"); // no compilation
} catch (Exception e) {
System.out.println("Exception:" + e.getMessage());
}
Even though the Eclipse IDE predicts the syso as dead code, why not java points it out. Even when it is getting compiled into bytecode the syso will never be executed. So why it is not taken as a compilation error. (i know its not a compilation error :| . May be, some other way of denoting it.) is it given for the programmer's choice ?
Aucun commentaire:
Enregistrer un commentaire