Java program to write exception when "hello" entered

 package execeptionhandling;

import java.util.Scanner;

public class Execeptionhandling {

public static void main(String args[])

 {

   String s1;

   Scanner sc=new Scanner(System.in);

   System.out.println("ENTER THE WORD:");

   s1= sc.next();

   if(s1.equals("hello"))

   {

  try

  {

       throw new MyException();

  }

 catch(MyException e)

    {

    System.out.println(e) ;

    }

  }

}

}

class MyException extends Exception{

   MyException()

   {

     System.out.println("The exception is rised!!!");

   }

}


Comments

Popular Posts