
class UseDefinedException extends Exception{
String msg = "";
int marks;
public UseDefinedException() ){
}
public UseDefinedException(String str){
super(str);
}
public String toString(){
if marks <= 50)
msg = "You have failed";
if marks > 50)
msg = "You have Passed";
return msg;
}
}
public class test{
public static void main(String args[]){
test t = new test();
t.mm();
}
public void mm(){
try{
int i=0;
if( i < 50)
throw new MyException();
}
catch(MyException ee1){
System.out.println("my ex"+ee1);
}
}
}
Hi,
I tried above code but getting Exception : MyException cannot be resolved to a type
at Interface.test1.me(test1.java:41) at Interface.test1.main(test1.java:34)
what is MyException and how it called ..please explain ..?

MyException should be a class name that defined custom exception. Here is an example of user-defiend exception.
class MyException extends Exception
{
public MyException(String message)
{
super(message);
}
}
class CustomException{
public static void main(String args[]) throws Exception
{
for(int i=1;i<=5;i++)
{
System.out.println("i= "+i);
if(i==3)
{
throw new MyException("My Exception Occurred");
}
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.