io.convergence_platform.common.helpers.ExceptionHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of service-lib Show documentation
Show all versions of service-lib Show documentation
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;
}
}