List of utility methods to do RuntimeException Create
RuntimeException | toRuntimeException(Exception e) to Runtime Exception return toRuntimeException(e, null);
|
RuntimeException | toRuntimeException(Exception e) Do never catch Throwables! return e instanceof RuntimeException ? (RuntimeException) e : new RuntimeException(e); |
RuntimeException | toRuntimeException(Exception ex) to Runtime Exception if (ex instanceof RuntimeException) { return (RuntimeException) ex; } else { return new RuntimeException(ex); |
RuntimeException | toRuntimeException(final Throwable e) Creates a RuntimeException from the Throwable if it isn't already a RuntimeException if (e == null) { return new NullPointerException("Problem without an Exception"); return e instanceof RuntimeException ? (RuntimeException) e : new RuntimeException(e); |
RuntimeException | toRuntimeException(Throwable e) convert Throwable to RuntimeException RuntimeException re = new RuntimeException(e); re.setStackTrace(e.getStackTrace()); e.printStackTrace(System.err); return re; |
RuntimeException | toRuntimeException(Throwable t) Always returns a RuntimeException using this sequential logic:
This method is usually called to convert checked Exceptions into unchecked ones. if (t == null) return new RuntimeException("This RuntimeException wraps a null cause"); else if (t instanceof Error) return new RuntimeException("This RuntimeException wraps an underlying Error (see cause)", t); else if (t instanceof RuntimeException) return (RuntimeException) t; else if (t instanceof Exception) return new RuntimeException("This RuntimeException wraps an underlying checked Exception (see cause)", ... |
RuntimeException | toRuntimeException(Throwable t) to Runtime Exception return new RuntimeException(t); |
RuntimeException | toRuntimeException(Throwable throwable) to Runtime Exception return throwable instanceof RuntimeException ? (RuntimeException) throwable : new RuntimeException(throwable); |
RuntimeException | toRuntimeException(Throwable throwable) Converts the given throwable into a RuntimeException , if necessary, and returns it. if (throwable instanceof Error) throw (Error) throwable; return throwable instanceof RuntimeException ? (RuntimeException) throwable : new RuntimeException(throwable); |
T | toRuntimeExceptionOr(Class Returns the given throwable if it is of the expected type and returns it, or converts it into a RuntimeException , if necessary, and throws it. if (exClass.isAssignableFrom(throwable.getClass())) return (T) throwable; if (throwable instanceof RuntimeException) throw (RuntimeException) throwable; if (throwable instanceof Error) throw (Error) throwable; throw new RuntimeException(throwable); |