City Suvidha...your one stop Search

Java Programs

Go Back to List

Program to implement the Exception Handling.
 

import java.lang.Exception;
class MyException extends Exception
{
MyException(String message)
{
super(message);
}
}

class TestMyException
{
public static void main(String args[])
{
int x=5,y=1000;
try
{
float z=(float)x/(float)y;
if(z<0.01)
{
throw new MyException("Num. ios too small");
}
}
catch(MyException e)
{
System.out.println("caught my exception");
System.out.println(e.getMessage());
}
finally
{
System.out.println("I m always here");
}
}
}
 

Output:

 

If any of you want to submit your programs and contribute to site please mail us at:

citysuvidha@gmail.com

Click here to have a look at  List of programs

You can download all the programs in a zip file also. For this you have to do one thing. Just register at the citysuvidha forum  and start any thread of any topic.  Once you start the thread and put your request, admin will automatically send you the desired zip file.