An Exception Adapter useful in order to LetExceptionsPropagateOnlyAsUncheckedExceptions
/**
* This adapter will wrap a non-runtime exception inside a runtime exception to allow it
* to propagate<p>
* It ensures that unchecked exceptions or exceptions that are already wrapped are not re-wrapped.<p>
* This is done to shield calling methods from implementation specific exceptions, and is
* close to the exception strategy used in C# and C++
*/
public class ExceptionAdapter {
public static RuntimeException toRuntimeException(Exception e) {
if(RuntimeException.class.isInstance(e)) return (RuntimeException) e;
else return new RuntimeException(e);
},
},
-- AndreParrie
CategoryJava | CategoryException