java-getopt icon indicating copy to clipboard operation
java-getopt copied to clipboard

System.err.println should not be used within an API

Open obourdon opened this issue 10 years ago • 3 comments

Considering the fact that your great API is supposed to be used in a lot of different contexts like web service (Tomcat, Jetty, ...) as well as applications/other APIs it is very annoying to have calls to System.err.println which

  1. may be do not produce any output (web service)
  2. may pollute the user program/other API using GnuGetopt

In my case I have replaced all calls to System.err.println to throw new IllegalArgumentException which leaves it to the user/programmer to decide what he wants to do with the Exception

obourdon avatar Jun 02 '14 14:06 obourdon

I second this – Errors should be thrown for the user of the API to handle, not effectively swallowed

nic-hartley avatar Dec 02 '15 12:12 nic-hartley

Hello. Thanks for your comments. The reason this API prints errors is because the original design goal was 100% compatibility with the glibc version. I will evaluate an option to turn this off for a future update.

arenn avatar Dec 06 '15 21:12 arenn

Good answer. Yours may turn out to be the better model On Dec 6, 2015 4:37 PM, "arenn" [email protected] wrote:

Hello. Thanks for your comments. The reason this API prints errors is because the original design goal was 100% compatibility with the glibc version. I will evaluate an option to turn this off for a future update.

— Reply to this email directly or view it on GitHub https://github.com/arenn/java-getopt/issues/3#issuecomment-162349813.

cdrasmussen avatar Dec 08 '15 01:12 cdrasmussen