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

com.softicar.platform.common.core.exception.CheckedExceptions Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.core.exception;

import com.softicar.platform.common.core.utils.CastUtils;

/**
 * Auxiliary methods for checked {@link Exception} handling.
 *
 * @author Oliver Richers
 */
public class CheckedExceptions {

	/**
	 * Converts the given {@link Throwable} into a {@link RuntimeException}.
	 * 

* The conversion is done by casting if possible. Otherwise the * {@link Throwable} will be wrapped by a new {@link RuntimeException}. * * @param throwable * the {@link Throwable} to convert (never null) * @return the converted {@link RuntimeException} */ public static RuntimeException toRuntimeException(Throwable throwable) { return CastUtils// .tryCast(throwable, RuntimeException.class) .orElseGet(() -> new RuntimeException(throwable)); } public static void wrap(IThrowingNullaryVoidFunction function) { try { function.apply(); } catch (RuntimeException exception) { throw exception; } catch (Exception exception) { throw new RuntimeException(exception); } } public static T wrap(IThrowingSupplier supplier) { try { return supplier.get(); } catch (RuntimeException exception) { throw exception; } catch (Exception exception) { throw new RuntimeException(exception); } } public static interface IThrowingNullaryVoidFunction { void apply() throws Exception; } public static interface IThrowingSupplier { T get() throws Exception; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy