Module de.carne
Package de.carne.util

Class Exceptions


  • public final class Exceptions
    extends java.lang.Object
    Utility class providing Exception/Throwable handling related functions.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Throwable getCause​(java.lang.Throwable exception)
      Checks and gets the submitted Throwable's causing exception.
      static java.lang.String getMessage​(@Nullable java.lang.Throwable exception)
      Gets an Throwable's best message.
      static java.lang.String getStackTrace​(java.lang.Throwable exception)
      Gets a Throwable's stack trace.
      static void ignore​(@Nullable java.lang.Throwable exception)
      Ignores a Throwable.
      static java.lang.RuntimeException toRuntime​(java.lang.Throwable exception)
      Makes a Throwable unchecked by wrapping it into a RuntimeException if needed.
      static java.lang.String toString​(java.lang.Throwable e)
      Determines the best textual representation of a Throwable.
      static void warn​(@Nullable java.lang.Throwable exception)
      Warns about a Throwable.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • toRuntime

        public static java.lang.RuntimeException toRuntime​(java.lang.Throwable exception)
        Makes a Throwable unchecked by wrapping it into a RuntimeException if needed.
        Parameters:
        exception - the Throwable to wrap.
        Returns:
        the created RuntimeException.
      • ignore

        public static void ignore​(@Nullable java.lang.Throwable exception)
        Ignores a Throwable.

        This function logs the Throwable using the trace log level and discards it.

        Parameters:
        exception - the Throwable to ignore (may be null).
      • warn

        public static void warn​(@Nullable java.lang.Throwable exception)
        Warns about a Throwable.

        This function logs the Throwable using the warning log level and discards it.

        Parameters:
        exception - the Throwable to warn about (may be null).
      • getMessage

        public static java.lang.String getMessage​(@Nullable java.lang.Throwable exception)
        Gets an Throwable's best message.

        This function returns a default message in case null is submitted. Otherwise it tries Throwable.getLocalizedMessage() and Throwable.getMessage() to get the best possible message. The former function do not return anything the Throwable's type is returned.

        Parameters:
        exception - the Throwable to get the message from.
        Returns:
        the Throwable's message.
      • getCause

        public static java.lang.Throwable getCause​(java.lang.Throwable exception)
        Checks and gets the submitted Throwable's causing exception.
        Parameters:
        exception - the Throwable to get the causing exception for.
        Returns:
        the causing exception of the submitted exception itself if no cause is set.
      • getStackTrace

        public static java.lang.String getStackTrace​(java.lang.Throwable exception)
        Gets a Throwable's stack trace.
        Parameters:
        exception - the Throwable to get the stack trace for.
        Returns:
        the Throwable's stack trace.
      • toString

        public static java.lang.String toString​(java.lang.Throwable e)
        Determines the best textual representation of a Throwable.
        Parameters:
        e - The Throwable to get the textual representation for.
        Returns:
        The Throwable's message or it's type (if no message is available).