In this first chapter from the book The Art of Java by Herbert Schildt and James Holmes, the authors highlight certain features of the Java programming language that separate it from other languages. The chapter also covers: memory management, Java's built-in support for multithreading, Java's approach to exceptions as compared to C++, Java's support of polymorphism, and how bytecode enables Java's "Write Once, Run Anywhere" ability and provides security. (ISBN 0-07-222971-3, McGraw-Hill/Osborne, 2003).
The conceptual framework for exceptions pre-dates Java. So, too, does the incorporation of exceptions into other programming languages. For instance, exceptions were added to C++ several years before Java was created. What makes Java’s approach to exceptions important is that they were part of the original design. They were not added after the fact. Exceptions are fully integrated into Java and form one of its foundational features.
A key aspect of Java’s exception mechanism is that its use is not optional. In Java, handling errors through the use of exceptions is the rule. This differs from C++, for example, in which exceptions are supported but are not fully integrated into the entire programming environment.
Consider the common situations of opening or reading from a file. In Java, when an error occurs during one of these operations, an exception is thrown. In C++, the methods that open or read from a file report an error by returning a special error code. Because C++ did not originally support exceptions, its library still relies on error return codes rather than exceptions, and your program must constantly check for possible errors manually. In Java, you simply wrap the file-handling code within a try/catch block. Any errors will automatically be caught.
Remember: this is chapter one of The Art of Java, by Herbert Schildt and James Holmes (McGraw-Hill/Osborne, ISBN 0-07-222971-3, 2003). Check it out at your favorite bookstore today. Buy this book now.