Java Blog

 
 
 
class MyException extends Exception
{
       private char detail;

       MyException(char c) 
       {
              detail=c;
       }

       public String toString()
       {
              return \"MyException[\"+detail+\"]\";
       }
}

class MyExc
{
        static void myfunc(char ch) throws MyException
        {
               System.out.println(\"Called myfunc(\"+ch+\")\");
               if(ch==\'0\' || ch==\'1\' || ch==\'2\' || ch==\'3\' || ch==\'4\' || ch==\'5\'
                   || ch==\'6\' || ch==\'7\' || ch==\'8\' || ch==\'9\')
                      throw new MyException(ch);
                System.out.println(\"Normal Exit...\");
        }

         public static void main(String args[])
         {
                try
                {
                       myfunc(\'g\');
                       myfunc(\'7\');
                }
                catch(MyException e)
                {
                       System.out.println(\"Caught \"+e);               
                }
         }
}


/*
            Output

Called myfunc(g)
Normal Exit...
Called myfunc(7)
Caught MyException[7]

*/