You can use single argument for throw statement, which is a throwable object. Objects are instances of any subclass of the Throwable class. Try to understand following code given below.
Code:
class ExceptionDemo extends Exception {
public ExceptionDemo(String msg){
super(msg);
}
}
public class Test {
static int divide(int first,int second) throws ExceptionDemo{
if(second==0)
throw new ExceptionDemo("can't be divided by zero");
return first/second;
}
public static void main(String[] args) {
try {
System.out.println(divide(4,0));
}
catch (ExceptionDemo excp) {
excp.printStackTrace();
}
}
}
Bookmarks