Package gw.util

Class GosuExceptionUtil


  • public class GosuExceptionUtil
    extends Object
    • Constructor Detail

      • GosuExceptionUtil

        public GosuExceptionUtil()
    • Method Detail

      • findExceptionCause

        public static Throwable findExceptionCause​(Throwable e)
        Given an Exception, finds the root cause and returns it. This may end up returning the originally passed exception if that was the root cause.
        Parameters:
        e - the Throwable whose root cause should be located.
        Returns:
        the root Throwable, or e if it is the root.
      • throwArgMismatchException

        public static void throwArgMismatchException​(IllegalArgumentException exceptionToWrap,
                                                     String featureName,
                                                     Class[] actualParameters,
                                                     Object[] args)
        This method can be used to provide a more informative type-mismatch exception message than the standard java reflection does with its IllegalArgumentException.
        Parameters:
        exceptionToWrap - - exception to wrap
        featureName - - feature being executed when the (e.g. "method" or "constructor")
        actualParameters - - the actual parameter types expected
        args - - the args passed to the feature
      • findException

        public static <T extends Throwable> T findException​(Class<T> exceptionTypeToFind,
                                                            Throwable t)
        Given an Exception and an Exception type to look for, finds the exception of that type or returns null if none of that type exist.
      • getStackTraceAsString

        public static String getStackTraceAsString​(Throwable t)
      • forceThrow

        public static RuntimeException forceThrow​(Throwable t)

        This method will force the Throwable object that is passed in to be rethrown, regardless if it is a checked exception or not, allowing a developer to side step dealing with or wrapping checked exceptions in java.

        This method "returns" a RuntimeException, so that you don't have to put spurious return statements after it is called, but the method never exits normally, so the return value is never used.

        An example usage would be:

           throw GosuExceptionUtil.forceThrow( myCheckedException );
         
        Parameters:
        t - the throwable object to be rethrown.
      • addContextInfo

        public static <T extends Throwable> T addContextInfo​(T t,
                                                             String ctxInfo)
      • addContextInfoImpl

        public static <T extends Throwable> T addContextInfoImpl​(T t,
                                                                 String ctxInfo)