









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










So far we have used exceptions to handle runtime errors using try and catch blocks Exceptions should really be used to pass the issues to other parts of code This is because other parts of code might have more information or need to act accordingly
If an exception is thrown, the method will terminate You can chain throws in this manner through multiple methods If all the methods (including main()) chain the throw, you will crash with angry red text (See: ChainThrow.java)
In addition to try and catch blocks, you can also put a finally block after the catch block
Every file you have made has been a class It should come as no surprise that Exceptions are simply a type of class as well (they simply store some information) Similar to classes, you might need to import an exception in order to be able to use it (See: ImportException.java)
When you override methods that you inherited, you can catch on less exceptions (more restrictive) Remember child's overridden method must be able to “fit into” the parent's method This means you...
Checked exceptions need to either..
= Checked exceptions = Unchecked
It is possible to nest try-catch, but it is generally frowned upon You should either make a method for the inside try-catch, or simply catch at the outside (remove inside try) In addition to giving headaches, the inner try exception can fall through to the outer catch if the inner catch did not actually catchDocsity.com