Package: org.codehaus.groovy.runtime

## [Java] Class StackTraceUtils

- org.codehaus.groovy.runtime.StackTraceUtils

-     public class StackTraceUtils
      extends Object

  Originally was grails.utils.GrailsUtils, removed some grails specific stuff. Utility methods removing internal lines from stack traces

  Since:
    1.5

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static String` | `STACK_LOG_NAME` | The logger name for sanitized stack traces.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public static void` | `addClassTest(Closure test)` Adds a groovy.lang.Closure to test whether the stack trace element should be added or not.
    `` | `public static Throwable` | `deepSanitize(Throwable t)` Sanitize the exception and ALL nested causes
    `` | `public static Throwable` | `extractRootCause(Throwable t)` Extracts the root cause of the exception, no matter how nested it is
    `` | `public static boolean` | `isApplicationClass(String className)` Determines whether the given class name is an application class (not a Groovy runtime class).
    `` | `public static void` | `printSanitizedStackTrace(Throwable t, PrintWriter p)` Prints the sanitized stack trace of the exception to the given writer.
    `` | `public static void` | `printSanitizedStackTrace(Throwable t)` Prints the sanitized stack trace of the exception to standard error.
    `` | `public static Throwable` | `sanitize(Throwable t)` Remove all apparently groovy-internal trace entries from the exception instance
    `` | `public static Throwable` | `sanitizeRootCause(Throwable t)` Get the root cause of an exception and sanitize it for display to the user

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### public static final String STACK_LOG_NAME

      The logger name for sanitized stack traces.

  - ### Method Detail

    - #### public static void addClassTest(Closure test)

      Adds a groovy.lang.Closure to test whether the stack trace element should be added or not.

      The groovy.lang.Closure will be given the class name as parameter. the return value decides if the element will be added or not.

      - true - trace element will be added to the trace
      - false - trace element will not be added to the trace
      - null - continue with next test
      Groovy truth will be used to determine true and false, null is excluded from defaulting to false here. If all tests have been executed and all of them skipped, then the groovy standard filtering will take place.
      Parameters:
        `test` - the testing groovy.lang.Closure

    - #### public static Throwable deepSanitize(Throwable t)

      Sanitize the exception and ALL nested causes

      This will MODIFY the stacktrace of the exception instance and all its causes irreversibly

      Parameters:
        `t` - a throwable
      Returns:
        The root cause exception instances, with stack trace modified to filter out groovy runtime classes

    - #### public static Throwable extractRootCause(Throwable t)

      Extracts the root cause of the exception, no matter how nested it is

      Parameters:
        `t` - a Throwable
      Returns:
        The deepest cause of the exception that can be found

    - #### public static boolean isApplicationClass(String className)

      Determines whether the given class name is an application class (not a Groovy runtime class). First checks any registered test closures, then checks against known Groovy packages.

      Parameters:
        `className` - the fully qualified class name to check
      Returns:
        `true` if the class is an application class, `false` if it's a Groovy runtime class

    - #### public static void printSanitizedStackTrace(Throwable t, PrintWriter p)

      Prints the sanitized stack trace of the exception to the given writer. Removes apparently groovy-internal trace entries.

      Parameters:
        `t` - the Throwable whose stack trace to print
        `p` - the PrintWriter to print to

    - #### public static void printSanitizedStackTrace(Throwable t)

      Prints the sanitized stack trace of the exception to standard error. Removes apparently groovy-internal trace entries.

      Parameters:
        `t` - the Throwable whose stack trace to print

    - #### public static Throwable sanitize(Throwable t)

      Remove all apparently groovy-internal trace entries from the exception instance

      This modifies the original instance and returns it, it does not clone

      Parameters:
        `t` - the Throwable whose stack trace we want to sanitize
      Returns:
        The original Throwable but with a sanitized stack trace

    - #### public static Throwable sanitizeRootCause(Throwable t)

      Get the root cause of an exception and sanitize it for display to the user

      This will MODIFY the stacktrace of the root cause exception object and return it

      Parameters:
        `t` - a throwable
      Returns:
        The root cause exception instance, with its stace trace modified to filter out groovy runtime classes