29import java.io.PrintStream;
31import org.jau.lang.ExceptionUtils.CustomStackTrace;
41@SuppressWarnings(
"serial")
43 final Throwable interruptSource;
59 public static InterruptedException
wrap(
final InterruptedException ie) {
77 public static InterruptedException
wrap(
final InterruptedException ie,
final InterruptSource source) {
95 this.interruptSource = interruptSource;
103 super(cause.getMessage());
105 this.interruptSource = interruptSource;
113 return interruptSource;
125 return (InterruptedException)super.getCause();
130 final StringBuilder sb =
new StringBuilder(256);
131 sb.append(getClass().getSimpleName()).append(
": ");
132 if (
null != interruptSource) {
133 sb.append(
"[sourced]");
135 sb.append(
"[unknown]");
137 final String m = getLocalizedMessage();
139 sb.append(
" ").append(m);
141 return sb.toString();
145 public final void printCauseStack(
final PrintStream s,
final String causeStr,
final int causeIdx,
final int stackDepth) {
146 final String s0 = causeStr+
"["+causeIdx+
"]";
147 s.println(s0+
" by "+getClass().getSimpleName()+
": "+getMessage()+
" on thread "+Thread.currentThread().getName());
149 if(
null != interruptSource ) {
155 public final void printStackTrace(
final PrintStream s,
final int causeDepth,
final int stackDepth) {
156 s.println(getClass().getSimpleName()+
": "+getMessage()+
" on thread "+Thread.currentThread().getName());
159 if(
null != interruptSource ) {
static int printCause(final PrintStream s, final String causeStr, Throwable cause, final int causeIdx, final int causeDepth, final int stackDepth)
Prints the given Throwable cause to the output PrintStream s.
static void dumpStack(final PrintStream out)
static InterruptSource currentThread()
Casts current java.lang.Thread to InterruptSource if applicable, otherwise returns null.
InterruptedException, which may include the source, see getInterruptSource().
static InterruptedException wrap(final InterruptedException ie)
Wraps the given InterruptedException into a SourcedInterruptedException if it is not yet of the desir...
InterruptedException getCause()
Returns the propagated InterruptedException, i.e.
SourcedInterruptedException(final InterruptedException cause, final Throwable interruptSource)
final void printStackTrace(final PrintStream s, final int causeDepth, final int stackDepth)
Custom printStackTrace method, similar to Throwable#printStackTrace(PrintStream, int,...
SourcedInterruptedException(final String message, final InterruptedException cause, final Throwable interruptSource)
final Throwable getInterruptSource()
Returns the source of the Thread#interrupt() call if known, otherwise null is returned.
static InterruptedException wrap(final InterruptedException ie, final InterruptSource source)
Wraps the given InterruptedException into a SourcedInterruptedException if it is not yet of the same ...
final void printCauseStack(final PrintStream s, final String causeStr, final int causeIdx, final int stackDepth)
Prints this Throwable as a cause to the output PrintStream s, not iterating over all inner causes!
Interface allowing Throwable specializations to provide their custom stack trace presentation.
Interface exposing java.lang.Thread#interrupt() source, intended for java.lang.Thread specializations...
Throwable getInterruptSource(final boolean clear)
Returns the source of the last interrupt() call.