Re: new RuntimeException(Throwable) vs SneakyThrows

2019-02-14 Thread Vladimir Sitnikov
Julian> Do you propose to ban ’throw new RuntimeException(e)’ in all code or just in tests? I'm 100.42% sure we should ban new RuntimeException(e) and all the other cases like "new Throwable(e)" in test code. pull/1042 touches test code only, so it is more-or-less simple to reason about. That is

Re: new RuntimeException(Throwable) vs SneakyThrows

2019-02-14 Thread Julian Hyde
Do you propose to ban ’throw new RuntimeException(e)’ in all code or just in tests? The alternative, ’throw rethrow(e)' is only available in test code (because rethrow lives in TestUtil). What should people do in non-test code? Continue to ’throw new RuntimeException’? Use guava’s ’throw Throwa

Re: new RuntimeException(Throwable) vs SneakyThrows

2019-02-14 Thread Stamatis Zampetakis
Thanks for starting this discussion Vladimir. Although sneaky throws pattern is a rather hacky way of propagating a checked exception it does improve its readability. I like it. Till now I never noticed how verbose was a checked exception wrapped in a runtime exception. I agree that the pattern n

Re: new RuntimeException(Throwable) vs SneakyThrows

2019-02-13 Thread Vladimir Sitnikov
Julian> then there is a real chance that people will instead write Julian> System.out.println(e); Isn't System.out banned already? Of course we would just ban it and that's it. Julian>new RuntimeException(e), which I don’t think is that bad It produces garbage in the exception stacktraces (e

Re: new RuntimeException(Throwable) vs SneakyThrows

2019-02-13 Thread Julian Hyde
If we ban } catch (FooException e) { throw new RuntimeException(e); } then there is a real chance that people will instead write } catch (FooException e) { System.out.println(e); } instead. So, let’s give them a good alternative, or just let them continue writing "new RuntimeEx

Re: new RuntimeException(Throwable) vs SneakyThrows

2019-02-13 Thread Enrico Olivelli
Vladimir, Il giorno mer 13 feb 2019 alle ore 21:49 Vladimir Sitnikov ha scritto: > > Hi, > > I've recently discovered that new RuntimeException(Throwable) results in a > duplicated error messages. > In fact Throwable#(Throwable) just calls cause.getMessage() and uses > it as its own message. > >

new RuntimeException(Throwable) vs SneakyThrows

2019-02-13 Thread Vladimir Sitnikov
Hi, I've recently discovered that new RuntimeException(Throwable) results in a duplicated error messages. In fact Throwable#(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