wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes java.io Mini API and Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "java.io Mini API and Exceptions" Watch "java.io Mini API and Exceptions" New topic
Author

java.io Mini API and Exceptions

Ulrich Vormbrock
Ranch Hand

Joined: Apr 15, 2010
Posts: 73
Hello,

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%)
 
jQuery in Action, 2nd edition
 
subject: java.io Mini API and Exceptions