/** * Throw runtime exception with format "reason + cause message + cause Throwable" * * @param reason Message to include in exception * @param t Wrapped exception */ public void throwRuntime(String reason, Throwable t) { throwRuntime(reason, Optional.of(t)); }
private static String formatReason(Pair<String, Optional<Throwable>> p) { return formatReason(p.getLeft(), p.getRight()); }
gTime = DatatypeFactory.newInstance().newXMLGregorianCalendar((GregorianCalendar) gc).normalize(); } catch (DatatypeConfigurationException e) { ErrorUtils.RuntimeErrors.ILLEGAL_STATE.throwRuntime("Unable to set the begin time due to", e);
@Test public void illegal_state_throws_exception_with_reason() throws Exception { exception.expect(IllegalStateException.class); exception.expectMessage("illegal state happened"); exception.expectCause(nullValue(Throwable.class)); ErrorUtils.RuntimeErrors.ILLEGAL_STATE.throwRuntime("illegal state happened"); }
@Test public void illegal_arg_throws_exception_with_reason() throws Exception { exception.expect(IllegalArgumentException.class); exception.expectMessage("illegal arg happened"); exception.expectCause(nullValue(Throwable.class)); ErrorUtils.RuntimeErrors.ILLEGAL_ARG.throwRuntime("illegal arg happened"); }
/** * Throw runtime exception with "reason". * * @param reason Message to include in exception */ public void throwRuntime(String reason) { throwRuntime(reason, Optional.empty()); }
@Test public void illegal_arg_throws_exception_with_reason_and_cause() throws Exception { exception.expect(IllegalArgumentException.class); exception.expectMessage("illegal arg happened"); exception.expectCause(instanceOf(IOException.class)); ErrorUtils.RuntimeErrors.ILLEGAL_ARG.throwRuntime("illegal arg happened", new IOException("bad io")); }
@Test public void illegal_state_throws_exception_with_reason_and_cause() throws Exception { exception.expect(IllegalStateException.class); exception.expectMessage("illegal state happened"); exception.expectCause(instanceOf(IOException.class)); ErrorUtils.RuntimeErrors.ILLEGAL_STATE.throwRuntime("illegal state happened", new IOException("bad io")); }