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

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

Go to download

a-base is a library of basic (hence the name) classes, most notably immutable collection classes with copy-on-write operations

The newest version!
package com.ajjpj.abase.util;


import com.ajjpj.abase.function.AFunction0;
import com.ajjpj.abase.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