Class ExceptionHelper

java.lang.Object
slash.common.helpers.ExceptionHelper

public class ExceptionHelper extends Object
Provides exception helpers
Author:
Christian Pesch
  • Constructor Details

    • ExceptionHelper

      public ExceptionHelper()
  • Method Details

    • isComputerOffline

      public static boolean isComputerOffline(Throwable throwable)
    • getLocalizedMessage

      public static String getLocalizedMessage(Throwable throwable)
    • getLocalizedMessage

      public static String getLocalizedMessage(Throwable throwable, String url)
      Like getLocalizedMessage(Throwable), but names the host of the given url, if any. Only an unreachable host is reported as offline: a server that accepts the connection and then does not answer in time, or fails the TLS handshake, is not the computer's fault.
    • getCauseChain

      public static List<Throwable> getCauseChain(Throwable throwable)
      Walks the cause chain from throwable to the deepest cause and returns every distinct throwable on the way, outermost first.

      The walk is cycle-safe: a throwable is only visited once (identity-based), so a self-referential (A -> A) or looping (A -> B -> A) chain, which a naive getCause() loop would follow forever, terminates. This is the single cause-chain traversal every other helper here (and DiagnosticReport) shares.

    • getRootCause

      public static Throwable getRootCause(Throwable throwable)
      Walks the cause chain to the deepest cause. A wrapper like ExceptionInInitializerError or InvocationTargetException carries the real fault (e.g. a NoClassDefFoundError for a missing JDK module) as its cause; this returns that fault instead of the wrapper. Cycle-safe via getCauseChain(java.lang.Throwable).
    • getMessageWithCauses

      public static String getMessageWithCauses(Throwable throwable)
      Renders the throwable and its whole cause chain as one line, e.g. "ExceptionInInitializerError caused by NoClassDefFoundError: jdk/net/Sockets". Surfaces the underlying fault that a single getMessage() hides -- the outermost message is often a generic "Could not initialize class ...". Cycle-safe via getCauseChain(java.lang.Throwable).
    • printStackTrace

      public static String printStackTrace(Throwable throwable)