Throwable getCause - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Throwable getCause method.

This code example shows how to use the following methods:getCause
        try { 
            return get(); 
        } catch (InterruptedException e) {
            throw new ElasticSearchInterruptedException(e.getMessage());
        } catch (ExecutionException e) {
            if (e.getCause() instanceof ElasticSearchException) {
                throw (ElasticSearchException) e.getCause();
            } else { 
                throw new TransportException("Failed execution", e);
            } 
        } 
    } 
 
    @Override 
    public V txGet(long timeout, TimeUnit unit) throws ElasticSearchException {
        try { 
            return get(timeout, unit);
        } catch (TimeoutException e) {
            throw new ElasticSearchTimeoutException(e.getMessage());
        } catch (InterruptedException e) {
8
CodeRank
This code example shows how to use the following methods:getCause
            throw rethrowExecutionException(e);
        } 
    } 
 
    static ElasticSearchException rethrowExecutionException(ExecutionException e) {
        if (e.getCause() instanceof ElasticSearchException) {
            ElasticSearchException esEx = (ElasticSearchException) e.getCause();
            Throwable root = esEx.unwrapCause();
            if (root instanceof ElasticSearchException) {
                return (ElasticSearchException) root;
            } 
            return new UncategorizedExecutionException("Failed execution", root);
        } else { 
            return new UncategorizedExecutionException("Failed execution", e);
        } 
    } 
 
    @Override 
    public void onResponse(L result) {
        set(convert(result));
8
CodeRank
This code example shows how to use the following methods:getCause, getMessage
   * @param ioe an I/O exception 
   * @return cause if the I/O exception is caused by a possible disk error; 
   *         null otherwise. 
   */  
  static IOException getCauseIfDiskError(IOException ioe) {
    if (ioe.getMessage()!=null && ioe.getMessage().startsWith(DISK_ERROR)) {
      return (IOException)ioe.getCause();
    } else { 
      return null; 
    } 
  } 
 
  /** 
   * Create a new file. 
   * @throws IOException  
   * if the file already exists or if the file cannot be created. 
   */ 
  public static File createTmpFile(Block b, File f) throws IOException {
    if (f.exists()) {
      throw new IOException("Failed to create temporary file for " + b
7
CodeRank
This code example shows how to use the following methods:getCause, getLocalizedMessage, getMessage
 
    /** 
     * @tests {@link java.nio.channels.IllegalBlockingModeException#IllegalBlockingModeException()} 
     */ 
    public void test_Constructor() { 
        IllegalBlockingModeException e = new IllegalBlockingModeException();
        assertNull(e.getMessage());
        assertNull(e.getLocalizedMessage());
        assertNull(e.getCause());
    } 
 
    /** 
     * @tests serialization/deserialization compatibility. 
     */ 
    @TestTargets({ 
        @TestTargetNew( 
            level = TestLevel.COMPLETE, 
            notes = "Verifies serialization/deserialization compatibility.", 
            method = "!SerializationSelf", 
            args = {} 
7
CodeRank
This code example shows how to use the following methods:getCause, getLocalizedMessage, getMessage
 
    /** 
     * @tests {@link java.nio.channels.NonReadableChannelException#NonReadableChannelException()} 
     */ 
    public void test_Constructor() { 
        NonReadableChannelException e = new NonReadableChannelException();
        assertNull(e.getMessage());
        assertNull(e.getLocalizedMessage());
        assertNull(e.getCause());
    } 
 
    /** 
     * @tests serialization/deserialization compatibility. 
     */ 
    @TestTargets({ 
        @TestTargetNew( 
            level = TestLevel.COMPLETE, 
            notes = "Verifies serialization/deserialization compatibility.", 
            method = "!SerializationSelf", 
            args = {} 
7
CodeRank
This code example shows how to use the following methods:getCause, getLocalizedMessage, getMessage
 
    /** 
     * @tests {@link java.nio.channels.ClosedSelectorException#ClosedSelectorException()} 
     */ 
    public void test_Constructor() { 
        ClosedSelectorException e = new ClosedSelectorException();
        assertNull(e.getMessage());
        assertNull(e.getLocalizedMessage());
        assertNull(e.getCause());
    } 
 
    /** 
     * @tests serialization/deserialization compatibility. 
     */ 
    @TestTargets({ 
        @TestTargetNew( 
            level = TestLevel.COMPLETE, 
            notes = "Verifies serialization/deserialization compatibility.", 
            method = "!SerializationSelf", 
            args = {} 
7
CodeRank
This code example shows how to use the following methods:getCause, getLocalizedMessage, getMessage
 
    /** 
     * @tests {@link java.nio.channels.ClosedByInterruptException#ClosedByInterruptException()} 
     */ 
    public void test_Constructor() { 
        ClosedByInterruptException e = new ClosedByInterruptException();
        assertNull(e.getMessage());
        assertNull(e.getLocalizedMessage());
        assertNull(e.getCause());
    } 
    /** 
     * @tests serialization/deserialization compatibility. 
     */ 
    @TestTargets({ 
        @TestTargetNew( 
            level = TestLevel.COMPLETE, 
            notes = "Verifies serialization/deserialization compatibility.", 
            method = "!SerializationSelf", 
            args = {} 
        ), 
7
CodeRank
This code example shows how to use the following methods:getCause, getLocalizedMessage, getMessage
 
    /** 
     * @tests {@link java.nio.channels.NonWritableChannelException#NonWritableChannelException()} 
     */ 
    public void test_Constructor() { 
        NonWritableChannelException e = new NonWritableChannelException();
        assertNull(e.getMessage());
        assertNull(e.getLocalizedMessage());
        assertNull(e.getCause());
    } 
 
    /** 
     * @tests serialization/deserialization compatibility. 
     */ 
    @TestTargets({ 
        @TestTargetNew( 
            level = TestLevel.COMPLETE, 
            notes = "Verifies serialization/deserialization compatibility.", 
            method = "!SerializationSelf", 
            args = {} 
7
CodeRank
This code example shows how to use the following methods:getCause, getLocalizedMessage, getMessage
 
    /** 
     * @tests {@link java.nio.channels.NotYetBoundException#NotYetBoundException()} 
     */ 
    public void test_Constructor() { 
        NotYetBoundException e = new NotYetBoundException();
        assertNull(e.getMessage());
        assertNull(e.getLocalizedMessage());
        assertNull(e.getCause());
    } 
 
    /** 
     * @tests serialization/deserialization compatibility. 
     */ 
    @TestTargets({ 
        @TestTargetNew( 
            level = TestLevel.COMPLETE, 
            notes = "Verifies serialization/deserialization compatibility.", 
            method = "!SerializationSelf", 
            args = {} 
7
CodeRank
This code example shows how to use the following methods:getCause, getLocalizedMessage, getMessage
 
    /** 
     * @tests {@link java.nio.channels.AsynchronousCloseException#AsynchronousCloseException()} 
     */ 
    public void test_Constructor() { 
        AsynchronousCloseException e = new AsynchronousCloseException();
        assertNull(e.getMessage());
        assertNull(e.getLocalizedMessage());
        assertNull(e.getCause());
    } 
 
    /** 
     * @tests serialization/deserialization compatibility. 
     */ 
    @TestTargets({ 
        @TestTargetNew( 
            level = TestLevel.COMPLETE, 
            notes = "Verifies serialization/deserialization compatibility.", 
            method = "!SerializationSelf", 
            args = {} 
7
CodeRank

Related Throwable getCause Questions & Answers:

getCause Method Overview
Returns the cause of this throwable or null if the cause is nonexistent or unknown.
See Code Examples for other Java 8 Throwable Methods: