Termination Handler

Understand a method that is called when an exception occurs.

We'll cover the following

Problem

Write a program that sets up a termination handler. The handler should get called when an unknown exception occurs. The handler should terminate program execution.

Note: You have to provide an integer input under the “Enter the input below” tab before pressing the “Run” button.

Sample runs

Here’s what you should see when you run the program.

Vector index entered by the user: 5
Control reached here

Vector index entered by the user: 15
Unknown exception… terminating
Terminate handler called

Coding solution

Here is a solution to the problem above.

Get hands-on with 1200+ tech skills courses.