Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The exception will have to be eventually handled somewhere, but it does not have to be in your <code>Parent</code> class. In your case, the method that calls <code>new Parent ()</code> might catch the exception, or throw it again to its calling method. </p> <p>E.g. </p> <pre><code>try { Parent p = new Parent (); } catch (FileNotFoundException fnfe) { // Handle exception } </code></pre> <p>Or, you could have something like:</p> <pre><code>private Parent methodCreatingParent () throws FileNotFoundException { return new Parent (); } private void someOtherMethod () { try { Parent p = methodCreatingParent (); } catch (FileNotFoundException fnfe) { // Handle exception } } </code></pre> <p>The <code>throws</code> keyword is used when a method that throws an exception (<code>Parent ()</code> in your case) does not have enough context information to handle the exception correctly.</p> <h3>Edit</h3> <p>As per @Hot Licks' comment, it can be possible to never handle the <code>FileNotFoundException</code>, using the following code:</p> <pre><code>public class TestClass { public static void main (String[] args) throws FileNotFoundException { Parent p = new Parent (); } } </code></pre> <p>In this case, the default exception handler would automatically handle the exception. The default handler prints the stack trace and stops the application. The handler to use can be specified via the method <code>Thread.setDefaultUncaughtExceptionHandler (Thread.UncaughtExceptionHandler eh)</code>.</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.
    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