作者彙整: Dave Schweisguth

Java Tip 134: When catching exceptions, don’t cast your net too wide

Java’s compile-time checking does a pretty good job of keeping exceptions safely caged—you can’t call a method that throws a checked exception without catching the exception or declaring that your own method throws that exception. (For a great discussion on checked and unchecked exceptions and when to use each, see “Designing with Exceptions” (JavaWorld, 1998).) The compiler will also sometimes stop you from catching an exception that isn’t thrown in the try block, but not always, and not when you need it most. This Java Tip discusses this second compile-time check.

To read this article in full, please click here

閱讀全文

分類: IT 資訊科技(信息技术), java 1 對 1 私人補習, 熱門新聞 | 標籤: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , | 在〈Java Tip 134: When catching exceptions, don’t cast your net too wide〉中留言功能已關閉

Java Tip 134: When catching exceptions, don’t cast your net too wide

Java’s compile-time checking does a pretty good job of keeping exceptions safely caged—you can’t call a method that throws a checked exception without catching the exception or declaring that your own method throws that exception. (For a great discussion on checked and unchecked exceptions and when to use each, see “Designing with Exceptions” (JavaWorld, 1998).) The compiler will also sometimes stop you from catching an exception that isn’t thrown in the try block, but not always, and not when you need it most. This Java Tip discusses this second compile-time check.

To read this article in full, please click here

閱讀全文

分類: IT 資訊科技(信息技术), java教學網站, 熱門新聞, 科技趣聞 | 標籤: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , | 在〈Java Tip 134: When catching exceptions, don’t cast your net too wide〉中留言功能已關閉