Exception occurs in try block and handled in catch block

If a statement in try block raised an exception, then the rest of the try block doesn't execute and control passes to the corresponding catch block. After executing the catch block, the control will be transferred to finally block(if present) and then the rest program will be executed.


\begin{lstlisting}
class TryCatch
{
public static void main (String[] args)
...
...ted
System.out.println(''Outside try-catch clause'');
}
}
\end{lstlisting}

Output


\begin{lstlisting}
Exception caught in Catch block
Outside try-catch clause
\end{lstlisting}