Class Exceptions


  • public class Exceptions
    extends Object
    Helper methods for handling exceptions
    Author:
    bratseth
    • Constructor Detail

      • Exceptions

        public Exceptions()
    • Method Detail

      • toMessageString

        public static String toMessageString​(Throwable t)

        Returns a user friendly error message string which includes information from all nested exceptions.

        The form of this string is e.getMessage(): e.getCause().getMessage(): e.getCause().getCause().getMessage()... In addition, some heuristics are used to clean up common cases where exception nesting causes bad messages.

      • findCause

        public static <T extends ThrowableOptional<T> findCause​(Throwable t,
                                                                  Class<T> clazz)
        Returns the first cause or the given throwable that is an instance of clazz
      • throwUnchecked

        public static RuntimeException throwUnchecked​(Throwable e)
        Allows treating checked exceptions as unchecked. Usage: throw throwUnchecked(e); The reason for the return type is to allow writing throw at the call site instead of just calling throwUnchecked. Just calling throwUnchecked means that the java compiler won't know that the statement will throw an exception, and will therefore complain on things such e.g. missing return value.