File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Mini API and Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark " Mini API and Exceptions" Watch " Mini API and Exceptions" New topic
Author Mini API and Exceptions

Ulrich Vormbrock
Ranch Hand

Joined: Apr 15, 2010
Posts: 73

studying table 6-1 (from K&B 6, page 450), I discovered some important details (or even traps) which are worth to be mentioned.
It deals with exceptions concerning the most important I/O classes - exceptions affecting methods and constructors, as well!

Below please find my summary of such methods and constructors - there are some crucial things which I want to communicate.

Normally, the "typical" methods close(), flush() and write() throw an IOException - nevertheless, if we apply these methods to a PrintWriter object, no exceptions must be handled (instead, a FileNotFoundException - subclass of IOException - can arise while instantiating the class PrintWriter).

I feel compelled to share these details with you, also because I can imagine that some of the typical and "awkward" Drag&Drop exam questions concerning I/O classes may contain these kinds of traps.

Let's consider the following piece of code:

Due to the fact that we use PrintWriter, there's nothing wrong with placing the code block containing lines 14 - 19 outside the try/catch block;
if we used the I/O class BufferedWriter, instead - we would run into trouble.

I'm not sure about the granularity concerning exam cram (maybe, such details are not covered by the exam), so please correct me if this subject goes too far and too much into detail.

SCJP 6 (88%), SCWCD (89%)
I agree. Here's the link:
subject: Mini API and Exceptions
It's not a secret anymore!