Hi,

I've recently discovered that new RuntimeException(Throwable) results in a
duplicated error messages.
In fact Throwable#<init>(Throwable) just calls cause.getMessage() and uses
it as its own message.

This makes exceptions harder to follow since the new RuntimeException(e) is
very often used just to overcome "checked exception" rule in Java.

I've recently committed a deduplicate PR to Avatica:
https://github.com/apache/calcite-avatica/pull/84
As you can see, it removed "RuntimeException: ..." nonsense and it made
exceptions easier to understand. For instance, see
https://github.com/apache/calcite-avatica/pull/84/files#diff-d499001f31481c5f7151a81380c01a60L332

I think we should avoid new RuntimeException(Throwable), and I wonder if we
should add that as a forbiddenapis rule.

You can find a PR for *test* code:
https://github.com/apache/calcite/pull/1042

I'm not sure if I should just go ahead and dodge new
RuntimeException(Throwable) from the main codebase as well.
Do you have any negative experience with sneaky-throws pattern?
I'm inclined to do so provided no-one objects within a week.

Vladimir

Reply via email to