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.
標籤彙整: Java虚拟机
Java Tip 134: When catching exceptions, don’t cast your net too wide
Java Tip 133: More on typesafe enums
Many Java developers, including myself, like using the typesafe constant idiom because it provides cleaner code by removing the need to validate whether a constant value is valid or in range. I don’t detail too much here, as the idiom is well documente… 閱讀全文
Java Tip 133: More on typesafe enums
Many Java developers, including myself, like using the typesafe constant idiom because it provides cleaner code by removing the need to validate whether a constant value is valid or in range. I don’t detail too much here, as the idiom is well documente… 閱讀全文
Java Tip 132: The taming of the thread
Threads can be nasty beasts. This is partly attributed to their delicate nature. Threads can die. If the causes of thread death are not in your code, then MutableThread may keep your code running. This article explores a solution using an object-orient… 閱讀全文
Java Tip 132: The taming of the thread
Threads can be nasty beasts. This is partly attributed to their delicate nature. Threads can die. If the causes of thread death are not in your code, then MutableThread may keep your code running. This article explores a solution using an object-orient… 閱讀全文
Java Tip 131: Make a statement with javac!
Often you may want to test a single piece of code. For example, say you forget how the % operator works with negative numbers, or you must determine how a certain API call operates. Writing, compiling, and running a small program repeatedly just to tes… 閱讀全文
Java Tip 131: Make a statement with javac!
Often you may want to test a single piece of code. For example, say you forget how the % operator works with negative numbers, or you must determine how a certain API call operates. Writing, compiling, and running a small program repeatedly just to tes… 閱讀全文
Java Tip 130: Do you know your data size?
Recently, I helped design a Java server application that resembled an in-memory database. That is, we biased the design toward caching tons of data in memory to provide super-fast query performance.Once we got the prototype running, we naturally decide… 閱讀全文
Java Tip 130: Do you know your data size?
Recently, I helped design a Java server application that resembled an in-memory database. That is, we biased the design toward caching tons of data in memory to provide super-fast query performance.Once we got the prototype running, we naturally decide… 閱讀全文
Java Tip 129: SGLayout—a layout manager for the rest of us
A good layout manager proves essential for creating a good graphical user interface (GUI), but many beginner developers find the standard Java layout managers difficult to master. Of these, BorderLayout and FlowLayout generally prove useful, but develo… 閱讀全文

