EffectHandlerException extends ConnectionException { public static EffectHandlerException in(Object effectHandler, Throwable cause) { EffectHandlerException e = new EffectHandlerException(cause); final StackTraceElement[] stackTrace = e.getStackTrace(); stackTrace[0] = new StackTraceElement(effectHandler.getClass().getName(), "apply", null, -1); e.setStackTrace(stackTrace); return e; } private  EffectHandlerException(Throwable throwable); static EffectHandlerException in(Object effectHandler, Throwable cause);  }
@Test public void shouldProvideAGoodStackTrace() throws Exception { final RuntimeException cause = new RuntimeException("hey"); assertThatThrownBy( () -> { throw EffectHandlerException.in(new PretendEffectHandler(), cause); }) .hasStackTraceContaining(PretendEffectHandler.class.getName()) .hasCause(cause); }