com.ajjpj.afoundation.util.AUnchecker Maven / Gradle / Ivy
package com.ajjpj.afoundation.util;
import com.ajjpj.afoundation.function.AFunction0;
import com.ajjpj.afoundation.function.AStatement0;
/**
* This class throws an arbitrary exception without requiring it to be declared in a throws clause
*
* @author arno
*/
public class AUnchecker {
public static void throwUnchecked(Throwable th) {
AUnchecker. doIt(th);
}
@SuppressWarnings("unchecked")
private static void doIt(Throwable th) throws T {
throw (T) th;
}
@SuppressWarnings("unused")
public static void executeUnchecked(AStatement0 extends Exception> callback) {
try {
callback.apply();
}
catch(Exception exc) {
throwUnchecked (exc);
}
}
public static R executeUnchecked(AFunction0 callback) {
try {
return callback.apply();
}
catch(Exception exc) {
throwUnchecked (exc);
return null; //for the compiler
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy