07.01.2013 Views

David Defour - Université de Perpignan

David Defour - Université de Perpignan

David Defour - Université de Perpignan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Why Generic Exception Rule is<br />

(Arguably) Too Strict<br />

• Listing each type is almost always best<br />

–So exceptions you didn’t expect don’t get caught there<br />

–So real failure-handling is not obscured<br />

• Sometimes combining is concise and safe<br />

345<br />

jeudi 26 janvier 12<br />

–E.g., if someString could be null, you could have either<br />

NumberFormatException or NullPointerException. But, in<br />

both cases, you just want to use original value for n.<br />

int n = 10;<br />

try {<br />

n = Integer.parseInt(someString);<br />

} catch(Exception e) { }

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!