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

io.convergence_platform.common.helpers.ExceptionHelper Maven / Gradle / Ivy

Go to download

Holds the common functionality needed by all Convergence Platform-based services written in Java.

The newest version!
package io.convergence_platform.common.helpers;

public class ExceptionHelper {
    public static void throwIf(boolean condition, String message) {
        if (condition) {
            throw new RuntimeException(message);
        }
    }

    public static void execute(ExceptionableBlock block) {
        try {
            block.run();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }

    public static  Type executeWithValue(ExceptionableBlockWithReturnValue block) {
        return executeWithValue(block, null);
    }

    public static  Type executeWithValue(ExceptionableBlockWithReturnValue block, Exception originalEx) {
        try {
            return block.run();
        } catch (Exception ex) {
            if (originalEx == null || !(originalEx instanceof RuntimeException)) {
                throw new RuntimeException(ex);
            }
            throw (RuntimeException) originalEx;
        }
    }

    public interface ExceptionableBlock {
        void run() throws Exception;
    }

    public interface ExceptionableBlockWithReturnValue {
        Type run() throws Exception;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy