This lesson briefs the syntax of using exceptions using try/catch blocks.

Suppose in integer division, we have been given the first integer as 4 and the other as 0, which is practically not possible. So, in a situation like this, the compiler doesn’t know what to do. The system may hang. To overcome these types of situations (exceptions (runtime errors)) exception handling methods were implemented.

For the purpose of Exception handling we will use 4 key words. They are try, catch, throw, finally. In this 4 key words try key word is used to monitor the exceptions which are there in our code.

The try key word contains the body. This block will be called as try block. We use to write our code in try block which may generates the exceptions.

The try block will be as follows.

Get hands-on with 1200+ tech skills courses.