Package io.molr.commons.util
Class Exceptions
- java.lang.Object
-
- io.molr.commons.util.Exceptions
-
public class Exceptions extends Object
-
-
Constructor Summary
Constructors Constructor Description Exceptions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Exception>
Texception(Class<T> exceptionClass, String message, Object... args)
Instantiate the provided exceptionClass
.static IllegalArgumentException
illegalArgumentException(String message, Object... args)
static IllegalStateException
illegalStateException(String message, Object... args)
static String
stackTraceFrom(Throwable t)
-
-
-
Method Detail
-
exception
public static <T extends Exception> T exception(Class<T> exceptionClass, String message, Object... args)
Instantiate the provided exceptionClass
. It will look for a constructor compatible withString
andThrowable
. In case such constructor does not exists, this method will throw anIllegalArgumentException
. The message can contain "{}" type placeholders, like with common logging APIs.- Type Parameters:
T
- the type of the exception- Parameters:
exceptionClass
- the type of the exception to instantiatemessage
- the message (which can contain "{}" type of placeholders)args
- the arguments to the message, which will replace the "{}" type placeholders. In case of a throwable, it is passed as the second argumet of the exception constructor.- Returns:
- an instance of the exception
- Throws:
IllegalArgumentException
- in case the exception of the given type does not have an appropriate constructor.
-
illegalStateException
public static IllegalStateException illegalStateException(String message, Object... args)
-
illegalArgumentException
public static IllegalArgumentException illegalArgumentException(String message, Object... args)
-
-