Java 8 RuntimeException - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 RuntimeException class.

This code example shows how to use the following methods:
        if (aClass != null) {
            try { 
                protectionSpecificHeader = aClass.newInstance();
 
            } catch (InstantiationException e) {
                throw new RuntimeException(e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            } 
        } 
        protectionSpecificHeader.parse(bufferWrapper);
        return protectionSpecificHeader;
 
    } 
 
    public void parse(ByteBuffer buffer) {
        data = buffer;
 
    } 
 
5
CodeRank
This code example shows how to use the following methods:
    public static void wait(Thread thread, int seconds) {
        try { 
            thread.wait(seconds * 1000);
        } 
        catch (InterruptedException e) {
            throw new RuntimeException(e);
        } 
    } 
 
    public static void sleep(int seconds) {
        try { 
            Thread.sleep(seconds * 1000);
        } 
        catch (InterruptedException e) {
            throw new RuntimeException(e);
        } 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:
    eatChar(delimiter);
  } 
 
  public void eatChar(char target) {
    if(pos < len && line[pos] != target) {
      throw new RuntimeException("expected [" + target + "] but got " + line[pos] + " in [" + new String(line, pos, len - pos) + "]");
    } 
    pos++;
  } 
 
  public boolean hasMore() { 
    return pos < len;
  } 
} 
5
CodeRank
This code example shows how to use the following methods:getCause
    try { 
      value = mBeanServer.getAttribute(oname, attName);
    } catch (RuntimeMBeanException e) {
      // UnsupportedOperationExceptions happen in the normal course of business, 
      // so no need to log them as errors all the time. 
      if (e.getCause() instanceof UnsupportedOperationException) {
        if (LOG.isTraceEnabled()) {
          LOG.trace("Getting attribute " + attName + " of " + oname + " threw " + e);
        } 
      } else { 
        LOG.error("getting attribute "+attName+" of "+oname+" threw an exception", e);
      } 
      return; 
    } catch (RuntimeErrorException e) {
      // RuntimeErrorException happens when an unexpected failure occurs in getAttribute 
      // for example https://issues.apache.org/jira/browse/DAEMON-120 
      LOG.debug("getting attribute "+attName+" of "+oname+" threw an exception", e);
      return; 
    } catch (AttributeNotFoundException e) {
      //Ignored the attribute was not found, which should never happen because the bean 
6
CodeRank
This code example shows how to use the following methods:getCause
    try { 
      value = mBeanServer.getAttribute(oname, attName);
    } catch (RuntimeMBeanException e) {
      // UnsupportedOperationExceptions happen in the normal course of business, 
      // so no need to log them as errors all the time. 
      if (e.getCause() instanceof UnsupportedOperationException) {
        LOG.debug("getting attribute "+attName+" of "+oname+" threw an exception", e);
      } else { 
        LOG.error("getting attribute "+attName+" of "+oname+" threw an exception", e);
      } 
      return; 
    } catch (RuntimeErrorException e) {
      // RuntimeErrorException happens when an unexpected failure occurs in getAttribute 
      // for example https://issues.apache.org/jira/browse/DAEMON-120 
      LOG.debug("getting attribute "+attName+" of "+oname+" threw an exception", e);
      return; 
    } catch (AttributeNotFoundException e) {
      //Ignored the attribute was not found, which should never happen because the bean 
      //just told us that it has this attribute, but if this happens just don't output 
      //the attribute. 
5
CodeRank
This code example shows how to use the following methods:printStackTrace, getCause
            Object fieldValues[] = { 1, 2, 3 }; 
            d.setFields(fieldNames, fieldValues);
            System.out.println("Didn't get expected exception");
            ok = false;
        } catch (RuntimeOperationsException e) {
            if (e.getCause() instanceof IllegalArgumentException) {
                System.out.println("Got expected exception:");
                ok = true;
            } else { 
                System.out.println("Got unexpected exception:");
                ok = false;
            } 
            e.printStackTrace(System.out);
        } catch (Exception e) {
            System.out.println("Got unexpected exception:");
            ok = false;
            e.printStackTrace(System.out);
        } 
        try { 
            System.out.println(

5
CodeRank
This code example shows how to use the following methods:printStackTrace, getCause
            Object fieldValues[] = { 1, 2, 3 }; 
            d.setFields(fieldNames, fieldValues);
            System.out.println("Didn't get expected exception");
            ok = false;
        } catch (RuntimeOperationsException e) {
            if (e.getCause() instanceof IllegalArgumentException) {
                System.out.println("Got expected exception:");
                ok = true;
            } else { 
                System.out.println("Got unexpected exception:");
                ok = false;
            } 
            e.printStackTrace(System.out);
        } catch (Exception e) {
            System.out.println("Got unexpected exception:");
            ok = false;
            e.printStackTrace(System.out);
        } 
        try { 
            System.out.println(

5
CodeRank
This code example shows how to use the following methods:printStackTrace, getTargetException
                                      new ModelMBeanAttributeInfo[] {mmbai},
                                      null, null, null); 
        try { 
            mmbi.setDescriptor(null, "attribute");
        } catch (RuntimeOperationsException e) {
            if (e.getTargetException() instanceof IllegalArgumentException) {
                System.out.println("Test passes: got a " +
                                   "RuntimeOperationsException wrapping an " + 
                                   "IllegalArgumentException"); 
                return true; 
            } else { 
                System.out.println("TEST FAILS: wrong exception:");
                e.printStackTrace(System.out);
                return false; 
            } 
        } catch (Exception e) {
            System.out.println("TEST FAILS: wrong exception:");
            e.printStackTrace(System.out);
            return false; 
        } 
5
CodeRank
This code example shows how to use the following methods:printStackTrace, getTargetException
                                      new ModelMBeanAttributeInfo[] {mmbai},
                                      null, null, null); 
        try { 
            mmbi.setDescriptor(null, "attribute");
        } catch (RuntimeOperationsException e) {
            if (e.getTargetException() instanceof IllegalArgumentException) {
                System.out.println("Test passes: got a " +
                                   "RuntimeOperationsException wrapping an " + 
                                   "IllegalArgumentException"); 
                return true; 
            } else { 
                System.out.println("TEST FAILS: wrong exception:");
                e.printStackTrace(System.out);
                return false; 
            } 
        } catch (Exception e) {
            System.out.println("TEST FAILS: wrong exception:");
            e.printStackTrace(System.out);
            return false; 
        } 
5
CodeRank
This code example shows how to use the following methods:printStackTrace
        catch (SystemException ex)
        { 
            // The OA could not be ran 
            // Display as much help as possible to the user track down the configuration problem 
            System.out.println("Trailmap Error: The ORB object adapter could not ran: " + ex);
            ex.printStackTrace();
        } 
    } 
 
} 
4
CodeRank

Related Java 8 RuntimeException Questions & Answers:

Other Java 8 RuntimeException Examples

3:	  File file = new File(directory + "/article.rss");
4:	  if (!file.exists()) {
5:	    throw new RuntimeException("File not found");
6:	  }
7:	  Log.e("Testing", "Starting to read");

Read More

4:				try {
5:					camera = Camera.open();
6:					params = camera.getParameters();
7:				} catch (RuntimeException e) {
8:					Log.e("Camera Error. Failed to Open. Error: ", e.getMessage());

Read More

83:					camera = Camera.open();
84:					params = camera.getParameters();
85:				} catch (RuntimeException e) {
86:					Log.e("Camera Error. Failed to Open. Error: ", e.getMessage());
87:				}

Read More

See Code Examples for Java 8 RuntimeException Methods: