自定义exception源代码

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());
    }
  }
}

你可能感兴趣的:(exception,class,string,import,北大青鸟)