• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.io Mini API and Exceptions

Ulrich Vormbrock
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic