Package gw.util

Class GosuExceptionUtil


  • public class GosuExceptionUtil
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T extends java.lang.Throwable>
      T
      addContextInfo​(T t, java.lang.String ctxInfo)  
      static <T extends java.lang.Throwable>
      T
      addContextInfoImpl​(T t, java.lang.String ctxInfo)  
      private static boolean areFilesEquals​(java.lang.StackTraceElement throwableElt, java.lang.StackTraceElement currentElt)  
      private static boolean areMethodsEquals​(java.lang.StackTraceElement throwableElt, java.lang.StackTraceElement currentElt)  
      static java.lang.RuntimeException convertToRuntimeException​(java.lang.Throwable t)  
      static <T extends java.lang.Throwable>
      T
      findException​(java.lang.Class<T> exceptionTypeToFind, java.lang.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.
      static java.lang.Throwable findExceptionCause​(java.lang.Throwable e)
      Given an Exception, finds the root cause and returns it.
      static java.lang.RuntimeException forceThrow​(java.lang.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.
      static java.lang.RuntimeException forceThrow​(java.lang.Throwable t, java.lang.String ctxInfo)  
      static java.lang.String getStackTraceAsString​(java.lang.Throwable t)  
      static void throwArgMismatchException​(java.lang.IllegalArgumentException exceptionToWrap, java.lang.String featureName, java.lang.Class[] actualParameters, java.lang.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.
      • Methods inherited from class java.lang.Object

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

      • GosuExceptionUtil

        public GosuExceptionUtil()
    • Method Detail

      • findExceptionCause

        public static java.lang.Throwable findExceptionCause​(java.lang.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​(java.lang.IllegalArgumentException exceptionToWrap,
                                                     java.lang.String featureName,
                                                     java.lang.Class[] actualParameters,
                                                     java.lang.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 java.lang.Throwable> T findException​(java.lang.Class<T> exceptionTypeToFind,
                                                                      java.lang.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.
      • convertToRuntimeException

        public static java.lang.RuntimeException convertToRuntimeException​(java.lang.Throwable t)
      • getStackTraceAsString

        public static java.lang.String getStackTraceAsString​(java.lang.Throwable t)
      • forceThrow

        public static java.lang.RuntimeException forceThrow​(java.lang.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.
      • forceThrow

        public static java.lang.RuntimeException forceThrow​(java.lang.Throwable t,
                                                            java.lang.String ctxInfo)
      • addContextInfo

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

        public static <T extends java.lang.Throwable> T addContextInfoImpl​(T t,
                                                                           java.lang.String ctxInfo)
      • areMethodsEquals

        private static boolean areMethodsEquals​(java.lang.StackTraceElement throwableElt,
                                                java.lang.StackTraceElement currentElt)
      • areFilesEquals

        private static boolean areFilesEquals​(java.lang.StackTraceElement throwableElt,
                                              java.lang.StackTraceElement currentElt)