During program execution an error can be thrown.
Instead of ending the program an error can be caught
and a certain
code can be executed.
Syntax for handling error:
Let's look at the following example:
Output:
Since an error is thrown in the try block, the code from the catch block is called.
Such example is division by zero:
Output: