Package com.landawn.abacus.util
Class ExceptionUtil
java.lang.Object
com.landawn.abacus.util.ExceptionUtil
Note: This class contains the methods copied from Apache Commons and Google Guava under Apache License v2.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E extends Throwable>
u.Optional<E>static <E extends Throwable>
u.Optional<E>static Throwable
Returns the specifiedthrowable
if there is no cause found in it (throwable.getCause() == null
).static String
static String
getErrorMessage
(Throwable e, boolean withExceptionClassName) static String
Gets the stack trace from a Throwable as a String.static boolean
static boolean
static boolean
static boolean
static boolean
static <E extends Throwable>
voidregisterRuntimeExceptionMapper
(Class<E> exceptionClass, Function<E, RuntimeException> runtimeExceptionMapper) static <E extends Throwable>
voidregisterRuntimeExceptionMapper
(Class<E> exceptionClass, Function<E, RuntimeException> runtimeExceptionMapper, boolean force) static RuntimeException
static RuntimeException
Converts the specifiedThrowable
to aRuntimeException
if it's a checkedexception
or anError
, otherwise returns itself.static RuntimeException
toRuntimeException
(Throwable e, boolean throwIfItIsError) Converts the specifiedThrowable
to aRuntimeException
if it's a checkedexception
, or throw it if it's anError
.static Exception
-
Method Details
-
registerRuntimeExceptionMapper
public static <E extends Throwable> void registerRuntimeExceptionMapper(Class<E> exceptionClass, Function<E, RuntimeException> runtimeExceptionMapper) - Type Parameters:
E
-- Parameters:
exceptionClass
-runtimeExceptionMapper
-
-
registerRuntimeExceptionMapper
public static <E extends Throwable> void registerRuntimeExceptionMapper(Class<E> exceptionClass, Function<E, RuntimeException> runtimeExceptionMapper, boolean force) - Type Parameters:
E
-- Parameters:
exceptionClass
-runtimeExceptionMapper
-force
-
-
toRuntimeException
- Parameters:
e
-- Returns:
-
toRuntimeException
Converts the specifiedThrowable
to aRuntimeException
if it's a checkedexception
or anError
, otherwise returns itself.- Parameters:
e
-- Returns:
- See Also:
-
toRuntimeException
Converts the specifiedThrowable
to aRuntimeException
if it's a checkedexception
, or throw it if it's anError
. Otherwise returns itself.- Parameters:
e
-throwIfItIsError
-- Returns:
-
tryToGetOriginalCheckedException
- Parameters:
e
-- Returns:
-
hasCause
- Parameters:
e
-targetExceptionType
-- Returns:
-
hasCause
- Parameters:
e
-targetExceptionTester
-- Returns:
-
hasSQLCause
- Parameters:
e
-- Returns:
-
hasIOCause
- Parameters:
e
-- Returns:
-
isNullPointerOrIllegalArgumentException
- Parameters:
e
-- Returns:
-
listCause
- Parameters:
e
-- Returns:
-
firstCause
Returns the specifiedthrowable
if there is no cause found in it (throwable.getCause() == null
).- Parameters:
e
-- Returns:
-
findCause
public static <E extends Throwable> u.Optional<E> findCause(Throwable e, Class<? extends E> targetExceptionType) - Type Parameters:
E
-- Parameters:
e
-targetExceptionType
-- Returns:
-
findCause
public static <E extends Throwable> u.Optional<E> findCause(Throwable e, Predicate<? super Throwable> targetExceptionTester) - Type Parameters:
E
-- Parameters:
e
-targetExceptionTester
-- Returns:
-
getStackTrace
Gets the stack trace from a Throwable as a String.
The result of this method vary by JDK version as this method uses
Throwable.printStackTrace(java.io.PrintWriter)
. On JDK1.3 and earlier, the cause exception will not be shown unless the specified throwable alters printStackTrace.- Parameters:
e
- theThrowable
to be examined- Returns:
printStackTrace(PrintWriter)
method
-
getErrorMessage
- Parameters:
e
-- Returns:
-
getErrorMessage
- Parameters:
e
-withExceptionClassName
-- Returns:
-