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]

*/

    Related Post:
  1. Corba program of UDP client server application which sends the news to the client. Server takes the news from the NewsDataFile located at the server

  2. An applet program of showing new document using showDocument(URL) method

  3. Socket program of HTTP Server

  4. Program to display following things on the client machine a)date and time of the server machine b)date and time of the client machine and difference

  5. Program which creates an Array of character. Make one function with one argument as a character and that function throw a user defined exception

  6. Program to declare and initialize Integer variables and print them on the Standard Output Device

  7. Program to generate Fibonacci Series of a given number

  8. An applet program to take user input and display

  9. Program to show an example of getting at characters in a String

  10. Corba program to develop a simple calculator with addition, subtraction, multiplication and division capabilities, data collection from client side

  11. Program to evaluate following investment equation V=P(1+R)^N

  12. Program to show an example of using user-defined package in a program

  13. Create an interface coversions. Which have the following functions Inchestomillimeters(), hptowatts(),wattstohp(),poundstogram(),gramtopounds()

  14. Program to show the use of Switch Statement for the same statement for several different case labels

  15. An applet program to display text

  16. Program to Concat Strings

  17. Program to declare, initialize and print a 2D array of integers

  18. An applet program to display sum of two number of textField

  19. Program to display text

  20. Program to check the start and end of a String