Tabnine Logo
Throwable.initCause
Code IndexAdd Tabnine to your IDE (free)

How to use
initCause
method
in
java.lang.Throwable

Best Java code snippets using java.lang.Throwable.initCause (Showing top 20 results out of 2,214)

origin: facebook/litho

/**
 * If you are chaining multiple Runnable together that are going to schedule each other within
 * their run() method, use this constructor to track their stacktraces across threads. The
 * required parameter here is the argument coming from {@link #tracedRun(Throwable)}.
 */
public ThreadTracingRunnable(Throwable prevTracingThrowable) {
 this();
 mTracingThrowable.initCause(prevTracingThrowable);
}
origin: org.netbeans.api/org-openide-filesystems

/** Copies anotation.
 * @param newEx new exception to annotate
 * @param oldEx old exception to take annotation from
 * @return newEx
 */
public static Throwable copyAnnotation(Throwable newEx, Throwable oldEx) {
  return newEx.initCause(oldEx);
}
origin: aNNiMON/Lightweight-Stream-API

/**
 * Returns inner value if there were no exceptions, otherwise throws the given {@code exception}.
 *
 * @param <E> the type of exception
 * @param exception  an exception to be thrown
 * @return inner value if there were no exceptions
 * @throws E if there were exceptions in supplier function
 */
public <E extends Throwable> T getOrThrow(E exception) throws E {
  if (throwable != null) {
    exception.initCause(throwable);
    throw exception;
  }
  return value;
}
origin: neo4j/neo4j

/**
 * @deprecated Use {@link Throwable#initCause(Throwable)} instead.
 */
@Deprecated
public static <T extends Throwable> T withCause( T exception, Throwable cause )
{
  try
  {
    exception.initCause( cause );
  }
  catch ( Exception failure )
  {
    // OK, we did our best, guess there will be no cause
  }
  return exception;
}
origin: wildfly/wildfly

private static <T extends Throwable> T copyCause(T newThrowable, Throwable originalThrowable) {
  Throwable cause = originalThrowable.getCause();
  if (cause != null) try {
    newThrowable.initCause(cause);
  } catch (IllegalStateException ignored) {
    // some exceptions rudely don't allow cause initialization
  }
  return newThrowable;
}
origin: apache/ignite

/**
 * Utility method that sets cause into exception and returns it.
 *
 * @param e Exception to set cause to and return.
 * @param cause Optional cause to set (if not {@code null}).
 * @param <E> Type of the exception.
 * @return Passed in exception with optionally set cause.
 */
public static <E extends Throwable> E withCause(E e, @Nullable Throwable cause) {
  assert e != null;
  if (cause != null)
    e.initCause(cause);
  return e;
}
/**
origin: square/retrofit

 @Override public void onError(Throwable throwable) {
  if (!terminated) {
   observer.onError(throwable);
  } else {
   // This should never happen! onNext handles and forwards errors automatically.
   Throwable broken = new AssertionError(
     "This should never happen! Report as a bug with the full stacktrace.");
   //noinspection UnnecessaryInitCause Two-arg AssertionError constructor is 1.7+ only.
   broken.initCause(throwable);
   RxJavaPlugins.onError(broken);
  }
 }
}
origin: neo4j/neo4j

/**
 * @deprecated Use {@link Throwable#addSuppressed(Throwable)} and {@link Throwable#initCause(Throwable)} where
 * appropriate instead.
 */
@Deprecated
public static <E extends Throwable> E combine( E first, E second )
{
  if ( first == null )
  {
    return second;
  }
  if ( second == null )
  {
    return first;
  }
  Throwable current = first;
  while ( current.getCause() != null )
  {
    current = current.getCause();
  }
  current.initCause( second );
  return first;
}
origin: org.apache.hadoop/hadoop-common

@SuppressWarnings("unchecked")
private static <T extends IOException> T wrapWithMessage(
  T exception, String msg) throws T {
 Class<? extends Throwable> clazz = exception.getClass();
 try {
  Constructor<? extends Throwable> ctor = clazz.getConstructor(String.class);
  Throwable t = ctor.newInstance(msg);
  return (T)(t.initCause(exception));
 } catch (Throwable e) {
  LOG.warn("Unable to wrap exception of type {}: it has no (String) "
    + "constructor", clazz, e);
  throw exception;
 }
}
origin: org.apache.hadoop/hadoop-common

@SuppressWarnings("unchecked")
private static <T extends IOException> T wrapWithMessage(
  final T exception, final String msg) throws T {
 Class<? extends Throwable> clazz = exception.getClass();
 try {
  Constructor<? extends Throwable> ctor = clazz
    .getConstructor(String.class);
  Throwable t = ctor.newInstance(msg);
  return (T) (t.initCause(exception));
 } catch (Throwable e) {
  LOG.warn("Unable to wrap exception of type " +
    clazz + ": it has no (String) constructor", e);
  throw exception;
 }
}
origin: redisson/redisson

  e.initCause(cause);
} catch (Throwable t) {
origin: facebook/litho

 @Override
 public final void run() {
  try {
   tracedRun(mTracingThrowable);
  } catch (Throwable t) {
   if (ComponentsConfiguration.enableThreadTracingStacktrace) {
    Throwable lastThrowable = t;
    while (lastThrowable.getCause() != null) {
     lastThrowable = lastThrowable.getCause();
    }
    lastThrowable.initCause(mTracingThrowable);
   }

   throw t;
  }
 }
}
origin: wildfly/wildfly

private static TraceInformation getOrAddTraceInformation(Throwable t) {
  if (t == null) {
    throw new NullPointerException("t is null");
  }
  Throwable c;
  while (! (t instanceof TraceInformation)) {
    c = t.getCause();
    if (c == null) try {
      t.initCause(c = new TraceInformation());
    } catch (RuntimeException e) {
      // ignored
    }
    t = c;
  }
  return (TraceInformation) t;
}
origin: square/retrofit

@Override public void onError(Throwable throwable) {
 if (!subscriberTerminated) {
  subscriber.onError(throwable);
 } else {
  // This should never happen! onNext handles and forwards errors automatically.
  Throwable broken = new AssertionError(
    "This should never happen! Report as a Retrofit bug with the full stacktrace.");
  //noinspection UnnecessaryInitCause Two-arg AssertionError constructor is 1.7+ only.
  broken.initCause(throwable);
  RxJavaPlugins.getInstance().getErrorHandler().handleError(broken);
 }
}
origin: jeasonlzy/okhttp-OkGo

  @Override
  public void onError(Throwable throwable) {
    if (!terminated) {
      observer.onError(throwable);
    } else {
      // This should never happen! onNext handles and forwards errors automatically.
      Throwable broken = new AssertionError("This should never happen! Report as a bug with the full stacktrace.");
      //noinspection UnnecessaryInitCause Two-arg AssertionError constructor is 1.7+ only.
      broken.initCause(throwable);
      RxJavaPlugins.onError(broken);
    }
  }
}
origin: ReactiveX/RxJava

  chain.initCause(e);
} catch (Throwable t) { // NOPMD
origin: org.netbeans.api/org-openide-util

private static AnnException findOrCreate0(Throwable t, boolean create) {
  if (t instanceof AnnException) {
    return (AnnException) t;
  }
  if (t.getCause() == null) {
    if (create) {
      t.initCause(new AnnException());
    }
    return (AnnException) t.getCause();
  }
  return findOrCreate0(t.getCause(), create);
}
origin: com.thoughtworks.xstream/xstream

public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
  Throwable throwable = (Throwable) source;
  if (throwable.getCause() == null) {
    try {
      throwable.initCause(null);
    } catch (IllegalStateException e) {
      // ignore, initCause failed, cause was already set
    }
  }
  throwable.getStackTrace(); // Force stackTrace field to be lazy loaded by special JVM native witchcraft (outside our control).
  getConverter().marshal(throwable, writer, context);
}
origin: jeasonlzy/okhttp-OkGo

@Override
public void onError(Throwable throwable) {
  if (!subscriberTerminated) {
    subscriber.onError(throwable);
  } else {
    Throwable broken = new AssertionError("This should never happen! Report as a bug with the full stacktrace.");
    //noinspection UnnecessaryInitCause Two-arg AssertionError constructor is 1.7+ only.
    broken.initCause(throwable);
    RxJavaHooks.getOnError().call(broken);
  }
}
origin: ReactiveX/RxJava

@Test
public void complexCauses() {
  Throwable e1 = new Throwable("1");
  Throwable e2 = new Throwable("2");
  e1.initCause(e2);
  Throwable e3 = new Throwable("3");
  Throwable e4 = new Throwable("4");
  e3.initCause(e4);
  Throwable e5 = new Throwable("5");
  Throwable e6 = new Throwable("6");
  e5.initCause(e6);
  CompositeException compositeException = new CompositeException(e1, e3, e5);
  assertTrue(compositeException.getCause() instanceof CompositeExceptionCausalChain);
  List<Throwable> causeChain = new ArrayList<Throwable>();
  Throwable cause = compositeException.getCause().getCause();
  while (cause != null) {
    causeChain.add(cause);
    cause = cause.getCause();
  }
  // The original relations
  //
  // e1 -> e2
  // e3 -> e4
  // e5 -> e6
  //
  // will be set to
  //
  // e1 -> e2 -> e3 -> e4 -> e5 -> e6
  assertEquals(Arrays.asList(e1, e2, e3, e4, e5, e6), causeChain);
}
java.langThrowableinitCause

Javadoc

Initializes the cause of this Throwable. The cause can only be initialized once.

Popular methods of Throwable

  • getMessage
    Returns the detail message string of this throwable.
  • printStackTrace
  • getCause
    Returns the cause of this throwable or null if the cause is nonexistent or unknown. (The cause is th
  • toString
    Returns a short description of this throwable. The result is the concatenation of: * the Class#getN
  • getStackTrace
    Provides programmatic access to the stack trace information printed by #printStackTrace(). Returns a
  • <init>
    Constructs a new throwable with the specified cause and a detail message of (cause==null ? null : ca
  • getLocalizedMessage
    Creates a localized description of this throwable. Subclasses may override this method in order to p
  • setStackTrace
    Sets the stack trace elements that will be returned by #getStackTrace() and printed by #printStackTr
  • addSuppressed
    Appends the specified exception to the exceptions that were suppressed in order to deliver this exce
  • fillInStackTrace
  • getSuppressed
    Returns the throwables suppressed by this.
  • countDuplicates
    Counts the number of duplicate stack frames, starting from the end of the stack.
  • getSuppressed,
  • countDuplicates,
  • getInternalStackTrace,
  • nativeFillInStackTrace,
  • nativeGetStackTrace,
  • fillInStackTrace0,
  • genStackTrace,
  • genStackTraceFromError,
  • getOurStackTrace

Popular in Java

  • Reactive rest calls using spring rest template
  • findViewById (Activity)
  • getSystemService (Context)
  • scheduleAtFixedRate (Timer)
  • Menu (java.awt)
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • Semaphore (java.util.concurrent)
    A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now