The throw Statement

This lesson explains in-depth the working of a throw statement.

The throw statement #

throw throws an exception object and this terminates the current operation of the program. The expressions and statements that are written after the throw statement are not executed. This behavior is according to the nature of exceptions: they must be thrown when the program cannot continue with its current task.

The exception types Exception and Error #

Only the types that are inherited from the Throwable class can be thrown. Throwable is almost never used directly in programs. The types that are actually thrown are types that are inherited from Exception or Error, which themselves are the types that are inherited from Throwable. For example, all of the exceptions that “Phobos” throws are inherited from either Exception or Error ...

Access this course and 1400+ top-rated courses and projects.