by narrator · 6y ago · 0 comments
try { //your code } catch (Exception e) { throw new RuntimeException(e); }
around it and you'll be fine.
The thing about Java is that the code lasts for a really long time because when it fails, it does so usually with an exception that points to the problem. When promises hang in NodeJS or memory corruption happens in C, it's much more annoying to track down problems.
private static <T extends Throwable> T sneakyThrow(Throwable ex) throws T {
throw (T) ex;
}
Due to generic type erasure, the entire throw clause gets erased so it looks like this method doesn't throw anything.If you can get your team to commit to a "let it crash" policy, though, then it's pretty doable.
Better to check if it’s a runtime exception and throw it again without wrapping it. Only wrap if it’s not a runtime exception. Also you should check if the thread was interrupted and, if so, set the interrupt flag again.
The worst part of this is having that dance littered throughout all your code.