All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.rajivprab.cava.CheckedExceptionWrapper Maven / Gradle / Ivy

package org.rajivprab.cava;

import java.io.PrintStream;
import java.io.PrintWriter;

/**
 * Wrapper for checked exceptions, that looks just like the underlying exception.
 *
 * Any stack-traces will show the stack-trace for where the underlying exception was thrown from,
 * and not where the CheckedExceptionWrapper was thrown from.
 * 

* Created by rprabhakar on 12/15/15. */ public class CheckedExceptionWrapper extends RuntimeException { private final Throwable e; public CheckedExceptionWrapper(Throwable e) { this.e = e; } public Throwable getUnderlying() { return e; } // Returns the underlying exception's cause, not the underlying exception itself // To get the underlying exception, use getUnderlying() @Override public Throwable getCause() { return e.getCause(); } @Override public String getLocalizedMessage() { return e.getLocalizedMessage(); } @Override public String getMessage() { return e.getMessage(); } @Override public StackTraceElement[] getStackTrace() { return e.getStackTrace(); } @Override public void printStackTrace() { e.printStackTrace(); } @Override public void printStackTrace(PrintStream s) { e.printStackTrace(s); } @Override public void printStackTrace(PrintWriter s) { e.printStackTrace(s); } @Override public String toString() { return getClass() + " around {\n" + e.toString() + "\n}"; } @Override public boolean equals(Object o) { if (this == o) return true; if (o instanceof CheckedExceptionWrapper) { CheckedExceptionWrapper that = (CheckedExceptionWrapper) o; return getUnderlying().equals(that.getUnderlying()); } else { return getUnderlying().equals(o); } } @Override public int hashCode() { return e.hashCode(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy