Is there a restriction on extending from Exception? The following code gives me an error - "Incompatible type"
However, if I extende MyException from RuntimeException or any other Exception, it compiles fine.
What am I missing here?
public class Exception1{
public void divByZero() throws MyException
{
int num1 = 10;
int num2 = 0;
if ( num2 == 0) throw new MyException("dividing by zero");
}
public static void main(
String args[])
{
try{
new Exception1().divByZero();
}
catch(MyException myEx){System.out.println("catching ");}
finally{System.out.println("finally in main");}
}
}
class MyException extends Exception{
MyException(String msg){
super(msg);
}
}