I want to create user-defined exception with addition but I get a compilation error.
class Test{
public static void main(String[] args){
int a=9, b=67, result;
result = a+b;
throw new Add("Addition has been performed");
}
}
class Add extends Throwable{
Add(){
printStackTrace();
}
Add(String message){
System.out.println(message);
printStackTrace();
}
}
The error is:
Practice.java:8: error: unreported exception Add; must be caught or declared to be thrown
throw new Add("Addition has been performed");