Exceptions in Java: Hierarchy and Types
Errors, checked exceptions and unchecked exceptions sit in one hierarchy, and knowing which is which decides how you should react.
try, catch, finally, throw, throws and custom exceptions.
5 notes
Errors, checked exceptions and unchecked exceptions sit in one hierarchy, and knowing which is which decides how you should react.
try guards a block, catch handles specific failures, finally always runs, and try with resources closes what you opened.
throw raises an exception now; throws declares that a method may raise one and leaves the handling to the caller.
A custom exception names a failure in the language of your domain, which makes handling precise and messages meaningful.
The rules that separate exception handling which helps from exception handling which hides bugs.