Learn Java Programming - Checked and Unchecked Exceptions Tutorial

Описание к видео Learn Java Programming - Checked and Unchecked Exceptions Tutorial

When it comes to compiling your source code, it is important to understand the difference between checked and unchecked exceptions. All exceptions are classes that are derived from the Throwable class. Memorizing the class hierarchy is the key to determining whether an exception will be a checked or an unchecked exception. There are two subclasses of the Throwable class, Error and Exception. Error and all of its subclasses down the hierarchy are all unchecked exceptions. Now here is where it gets strange ... all subclasses of Exception are checked exceptions except for RuntimeException and all of its subclasses. RuntimeException and all of its subclasses down the hierarchy are unchecked exceptions.

As the Java compiler is compiling your source code, any statements that invoke methods or constructors that throw unchecked exceptions are given the green light and not required to be enclosed in a try block or specified in the throws list.
Any statements – in your source code – that invoke methods or constructors that throw checked exceptions are stopped at the red light and checked to make sure that they are enclosed in a try block or specified in the throws list.
I haven't gone over how to use the throws keyword just yet, so don't worry about that.

Комментарии

Информация по комментариям в разработке