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

com.ajjpj.afoundation.util.AUnchecker Maven / Gradle / Ivy

There is a newer version: 1.0-pre19
Show newest version
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 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