com.arjuna.ats.jta.cdi.SneakyThrow Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of narayana-jta Show documentation
Show all versions of narayana-jta Show documentation
Narayana: ArjunaJTA narayana-jta (jta uber jar)
The newest version!
/*
Copyright The Narayana Authors
SPDX-License-Identifier: Apache-2.0
*/
package com.arjuna.ats.jta.cdi;
/**
* An utility class which makes possible to throw any exception as a {@link RuntimeException}.
* It means to throw checked exception (subtype of Throwable or Exception) as un-checked exception.
* This considers the Java 8 inference rule that states that a {@code throws E} is inferred as {@code RuntimeException}.
*/
public class SneakyThrow {
private SneakyThrow() {
throw new IllegalStateException("utility class, do not instance");
}
/**
* This method can be used in {@code throw} statement
* such as: {@code throw sneakyThrow(exception);}.
*/
@SuppressWarnings("unchecked")
public static void sneakyThrow(Throwable e) throws E {
throw (E) e;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy