A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Write a program for exception catch with finally block

program to Print args parameter of main method and length of args

Program For Custom Exception With Try & Finally





import java.lang.Exception;

class MyException extends Exception 
{
   MyException(String message)
   {
     super(message);
   }
}

class Testcustom
{
   public static void main(String args[]) 
   {
     int x = 5;
     int y = 1000;
     try 
     {
        float z = (float) x / (float) y;
        if (z < (0.01))
        {
            throw new MyException("the number is too small");
        }
     }
     catch (MyException e) 
     {
        System.out.println("caught my exception");
        System.out.println(e.getMessage());
     }
     finally 
     {
        System.out.println("I am always there");
     }
   }
}


OutPut:-
caught my exception
the number is too small
I am always there











LEARN TUTORIALS

.

.