You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
897 B
Java

Throwing User defined Exception
public class MyException extends Exception
{
String msg = "";
int marks;
public MyException()
{
}
public MyException(String str)
{
super(str);
}
public String toString()
{
if(marks <= 40)
msg = "You have failed";
if(marks > 40)
msg = "You have Passed";
return msg;
}
}
public class test
{
public static void main(String args[])
{
test t = new test();
t.dd();
}
public void dd()
{
try
{
int i=0;
if( i < 40)
throw new MyException();
}
catch(MyException ee1)
{
System.out.println("my ex"+ee1);
}
}
}