MyException.java
package fengbolai;
public class MyException extends Throwable{
public String getMessage(){
return "my error";
}
}
A.java
package fengbolai;
public class A {
public void myFunction() throws MyException {
throw new MyException();
}
}
B.java
package fengbolai;
import java.io.*;
public class B {
public static void main(String[] args) {
A a = new A();
try {
a.myFunction();
}
catch (MyException me) {
System.out.println(me.getMessage());
}
}
}