What is the try block in Java?

A try/catch block is placed around the code that might generate an exception. Code within a try/catch block is referred to as protected code, and the syntax for using try/catch looks like the following –


try {
   // Protected code
} catch (ExceptionName e1) {
   // Catch block

The code which is prone to exceptions is placed in the try block. When an exception raised inside a try block, instead of terminating the program JVM stores the exception details in the exception stack and proceeds to the catch block.

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 25-Feb-2020


Kickstart Your Career

Get certified by completing the course

Get Started