CH11 - Exceptions and Localization Flashcards
Unchecked Exception
An unchecked exception is any exception that does not need to be declared or handled by the application code it is thrown.
Unchecked exceptions are often referred to as runtime exceptions.
Error
Error means something went so horribly wrong that your program should not attempt to recover from it.
Throwable
Throwable is that it’s the parent class of all exceptions, including the Error class.
While you can handle Throwable and Error exceptions, it is not recommended you do so in your app code.
Checked Exception
Subclass of Exception but not subclass of RuntimeException
Unchecked Exception
Subclass of RuntimeException
Overriding method with Exception
An overridden method may not declare any new or broader checked exceptions that the method it inherits.
An overridden method in a subclass is allowed to declare fewer exceptions than the superclass or interface.
try-with-resources
Only classes that implement the AutoCloseable interface can be used in a try-with-resources statement.
Inheriting AutoClosable requires implementing a compatible close() method
Closable
Closeable extends AutoClosable they are both supported in try-with-resources statements.
Difference Closeable’s close() method declares IOException, while AutoCloseable’s close() method declares Exception.
Scope of Try-With-Resources
The resources created in the try clause are in scope only within the try block.
This is anoter way to remember that the implicit finally runs before any catch/finally blocks that you code yourself.