Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can try and do nothing about it:</p> <pre><code>public static void exceptionTest() { makeNullPointer(); //The compiler allows me not to check this try { throwAnException(); //I'm forced to handle the exception, but I don't want to } catch (Exception e) { /* do nothing */ } } </code></pre> <p>Bear in mind, in <em>real life</em> this is extemely <strong>ill-advised</strong>. That can hide an error and keep you searching for dogs a whole week while the problem was really a cat(ch). <sub><sup> (Come on, put at least a <code>System.err.println()</code> there - Logging is the best practice here, as suggested by @BaileyS.)</sup></sub></p> <p><a href="http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html" rel="nofollow noreferrer">Unchecked exceptions in Java</a> extend the <code>RuntimeException</code> class. Throwing them will not demand a <code>catch</code> from their clients:</p> <pre><code>// notice there's no "throws RuntimeException" at the signature of this method public static void someMethodThatThrowsRuntimeException() /* no need for throws here */ { throw new RuntimeException(); } </code></pre> <p>Classes that extend <code>RuntimeException</code> won't require a <code>throws</code> declaration as well.</p> <p>And <a href="http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html" rel="nofollow noreferrer">a word from Oracle</a> about it:</p> <blockquote> <p>Here's the bottom line guideline: If a client can reasonably be expected to recover from an exception, make it a checked exception. If a client cannot do anything to recover from the exception, make it an unchecked exception.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload