It is not a design error. It is a proper design meant to be used in a situation when you write an output and you want errors to be ignored.
As a typical use case, the System.out
and System.err
were already mentioned, but the reason is not relaxed handling for convenience or smooth C/C++ transitions . It is a desired handling of a situation like this:
- you start an application in a console
- it produces output to the std out/err
- you close the console, but you want the application to continue in the background
In this situation, depending on the system implementation, it could happen that System.out
or System.err
would fail after the console is closed, but you don't want that to crash your application. The application is wanted to continue to run in the background and the output is meant to be scraped. That's what PrintWriter
does.
If you care about errors during the output, use FileWriter
or OutputStreamWriter
.
If you need some of the methods available in PrintWriter
and not available in FileWriter
, create your own TextWriter extending FileWriter
or OutputStreamWriter
.