What is the try block in Java?

Java 8Object Oriented ProgrammingProgramming

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.

Published on 08-Feb-2018 14:13:21