programming-examples/java/Core_Java/Throwing User defined Exception.java

48 lines
897 B
Java
Raw Normal View History

2019-11-15 12:59:38 +01:00
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);
}
}
}