class MyException extends Exception { public String toString() {
return "negative";
}
}
public class ExceptionDemo {
public static void mySqrt(int a) throws MyException {
if (a < 0)
throw new MyException();
System.out.println(Math.sqrt(a));
}
public static void main(String args[]) {
try {
mySqrt(25);
mySqrt(-5);
} catch (MyException e) {
System.out.println("Caught " + e);
}
}
}