-
Notifications
You must be signed in to change notification settings - Fork 476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subclass RuntimeException? #313
Comments
Yes, checked Exceptions are considered harmful nowadays. Where did you get a NPE ? If this is caused by influxdb-java it can be considererd as a bug and should reported as such. Im not keen to introduce a new exception for no clear reason. |
The NPE was caused by a bug in my own code, which ended up being caught by the try-catch block surrounding the influxdb-java calls, which is undesirable. To make the whole thing clearer by an example:
If there was a custom InfluxException (extending RuntimeException), this would allow for this error handling:
Not only NPEs cause this behaviour, but a ton of other Exeptions, too, as can be seen from the docs: https://docs.oracle.com/javase/7/docs/api/java/lang/RuntimeException.html |
Here is a reference to back up my claim: https://www.securecoding.cert.org/confluence/display/java/ERR07-J.+Do+not+throw+RuntimeException%2C+Exception%2C+or+Throwable |
As far as I can see, the error handling in influxdb-java consists of Exceptions wrapped in a
RuntimeException
, like here: https://github.com/influxdata/influxdb-java/blob/master/src/main/java/org/influxdb/impl/InfluxDBImpl.java#L101I presume that one reason for doing so was to make the Exception handling unchecked, which I am in principle not opposed to. However, this pattern forces me to surround calls to influxdb-java in try-catch blocks catching
RuntimeExceptions
. I just now ran into a case where I had a NullPointerException within this try-catch block that, being an instance ofRuntimeException
also gets caught. Wouldn't it be much better to create a custom exception, e.g.InfluxException
that inherits fromRuntimeException
? This way client-side error handling gets much easier and if I am not mistaken, it would not even break existing code.The text was updated successfully, but these errors were encountered: