- An Unchecked Exception inherits from RuntimeException (which extends from Exception). The JVM treats RuntimeException differently as there is no requirement for the application-code to deal with them explicitly.
- A Checked Exception inherits from the Exception-class. The client code has to handle the checked exceptions either in a try-catch clause or has to be thrown for the Super class to catch the same. A Checked Exception thrown by a lower class (sub-class) enforces a contract on the invoking class (super-class) to catch or throw it.
- Errors (members of the Error family) are usually thrown for more serious problems, such as OutOfMemoryError (OOM), that may not be so easy to handle.
Throwable has two sub class routes, Error and Exception
Error is thown and no checked - eg for out of mem errors - unhandled unexpected exceptions
Exception has two defined subclass logics
unchecked exceptions - you dont have to handle this in the code - jvm treats it different
checl exeptions need to be handled by try eventuallyand can be thrown up the calling method stack chain- eg defined int he method signature as throws
No comments:
Post a Comment