Exceptions Flashcards
What is the difference between final, finalize(), and finally?
Final is a keyword that prevents any changes from being made to the variable/method/class attached to it
finalize() is a method that is used to perform cleanup before the garbage is collected
Finally is a block in exception handling that will always run regardless of exceptions
Explain throw, throws, Throwable
throw is a keyword that is used to throw an exception manually
throws is a keyword which is used in the method signature to indicate that a method may need to throw that exception
Throwable is a super class for all types of errors and exceptions. If you want to create your own exception, it must extend this class
Do you need a catch block? Can you have more than one? Is there any order to follow?
You do not need catch block after a try statement as long as you have a finally block
There can be multiple catch blocks, but only one will be executed at a time
Each catch block must have a different exception handler
What is the base class of all exceptions? What interface do they all implement?
Throwable is the base class of all exceptions, and they all implement the Serializable interface
List some checked and unchecked exceptions
Checked: IOException, ClassNotFoundException, FileNotFoundException
Unchecked: ArithmeticException, ArrayIndexOutOfBounds