Package slash.common.helpers
Class ExceptionHelper
java.lang.Object
slash.common.helpers.ExceptionHelper
Provides exception helpers
- Author:
- Christian Pesch
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetCauseChain(Throwable throwable) Walks thecausechain fromthrowableto the deepest cause and returns every distinct throwable on the way, outermost first.static StringgetLocalizedMessage(Throwable throwable) static StringgetLocalizedMessage(Throwable throwable, String url) LikegetLocalizedMessage(Throwable), but names the host of the given url, if any.static StringgetMessageWithCauses(Throwable throwable) Renders the throwable and its whole cause chain as one line, e.g.static ThrowablegetRootCause(Throwable throwable) Walks thecausechain to the deepest cause.static booleanisComputerOffline(Throwable throwable) static StringprintStackTrace(Throwable throwable)
-
Constructor Details
-
ExceptionHelper
public ExceptionHelper()
-
-
Method Details
-
isComputerOffline
-
getLocalizedMessage
-
getLocalizedMessage
LikegetLocalizedMessage(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
Walks thecausechain fromthrowableto 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 naivegetCause()loop would follow forever, terminates. This is the single cause-chain traversal every other helper here (andDiagnosticReport) shares. -
getRootCause
Walks thecausechain 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 viagetCauseChain(java.lang.Throwable). -
getMessageWithCauses
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 viagetCauseChain(java.lang.Throwable). -
printStackTrace
-