Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>No. the <code>throws BlahException</code> clause tells the compiler that your function <em>might</em> throw a BlahException and that this should be caught by the caller. For example:</p> <pre><code>class ExceptionThrower { void someFunction() { for(int i =0; i&lt;10;i++) if(i==4) throw new Exception(); } public static void main(String args[]) { new ExceptionThrower().someFunction(); } } </code></pre> <p>This program will not compile, because it can throw an exception of type <code>Exception</code>, and the exception has neither been caught nor declared to be thrown. </p> <p>However, the following code will compile fine.</p> <pre><code>class ExceptionThrower { void someFunction() throws Exception { for(int i =0; i&lt;10;i++) if(i==4) throw new Exception(); } public static void main(String args[]) { try { new ExceptionThrower().someFunction(); } catch(Exception e) { e.printStackTrace(); } } } </code></pre> <p>Essentially, you are telling the compiler that this function <em>might</em> throw an Exception that is not handled inside the function itself. These types of exceptions are all subclasses of <code>java.lang.Exception</code> and are called <em>checked exceptions</em>. Other exceptions that indicate a catastrophic failure caused by bugs in the program itself, rather than by a condition such as malformed input are subclasses of <code>java.lang.RuntimeException</code> and these are called <em>unchecked exceptions</em>. In short, unchecked exceptions can be thrown without a <code>throws</code> clause in the method signature, while any checked exceptions must be indicated there.</p> <p>For a discussion of checked vs. unchecked exceptions see <a href="http://www.javapractices.com/topic/TopicAction.do?Id=129" rel="noreferrer">http://www.javapractices.com/topic/TopicAction.do?Id=129</a></p>
    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. 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