10.1 Understanding Exceptions Flashcards
📝️ What is a Java Exception?
An exception is an event that disrupts/alter the normal flow of an application
📝️ What is the java.lang.Throwable class?
It’s the Java superclass for all objects that represent an Exception event.
📝️ What are the key subclasses of Throwable
(Exception-types)?
- > Error
- > RuntimeExceptions [Unchecked]
- > Exceptions [Checked Exceptions]
📝️What does the 💥️Error💥️ class represents (examples)?
- > An Error means something went so horribly wrong that your program should not attempt to recover from it.
e. g: The disk drive “disappeared” or the program ran out of memory.
📝️ What does 💥️Checked Exception💥️ mean in Java?
- > Checked exceptions include any class that inherits Throwable, but does NOT inherit from Error nor RuntimeException classes.
- > It’s an exception that needs to be anticipated in other words, it must be caught or declared.
📝️ What is an 💥️Unchecked Exception💥️ class?
o An Unchecked exception is a RuntimeException or any of its subclasses.
o It does NOT have to be handled nor declared.
o This kind of exceptions can be thrown by the JVM itself or the programmer code.
What Exception classes…
are Catcheable or Have to be Declared (Table)?
👉️ Error |✅|✅| ⚠️ You shouldn’t but you can
👉️ Unchecked Exc. |✅|✅| ❓️ You can but you don’t have to
👉️ Checked Excep |✅|✅| 💪️You have to
📝️ What does the 💥️HANDLE OR DECLARE💥️ rule means?
It means that Checked Exceptions should be handle or declared
👉️ handle -> 🕵♂️️’throw’ Wrapped in compatible try and catch blocks
👉️ declared -> 🕵♂️️’throws’ Defined that this method ‘throws’ a certain exception in the method signature …(someone else will handle it.)
📝️ What are the keywords used to declare and delegate exception handling (when)?
- > throw - When a particular condition is matched we can throw an Exception …e.g: throw new IOException();
- > throws - It is used at the end of a method declaration …e.g: throws IOException
📝️ What is the ‘throw’ keyword used for?
o It’s used to declare a new exception (throw) or re-throw an existing one.
-> It goes as an statement inside a code block.
📝️ What does throws statement mean in java?
-> The throws keyword indicates that a certain method can potentially “throw” an specific exception.