1 package testDate; 2 //自定义异常 3 public class MyException extends Exception{ 4 public MyException(){ 5 6 } 7 public MyException(String message){ 8 super(message); 9 } 10 } 11 class TestMyException{ 12 void test()throws MyException{ 13 14 } 15 public static void main(String[] args) { 16 try { 17 new TestMyException().test(); 18 } catch (MyException e) { 19 e.printStackTrace(); 20 } 21 } 22 }