Write a program to demonstrate the use of try,catch or finally block.

public class TryCatchFinally
{
    public static void main(string args[])
	{
	/**Exception will occur here,after catch block
	*The control will goto finally block.
	*/
	    try
		{
		   int i=5/0;
		}
		catch(Exception ex)
		{
		   System.out.printIn("Inside 1st catch Block");
		}
		finally
		{
		   System.out.printIn("Inside 1st finally block");
		}
		/**After executing try block
		*the control will goto finally block.
		*/
		try
		{
		   int i=5/5;
		}
		catch(Exception ex)
		{
		   System.out.printIn("Inside 2nd catch Block");
		}
		finally
		{
		   System.out.printIn("Inside 2nd finally block");
		}
	}
}
	
Show Buttons
Hide Buttons