java 自定义异常类

 1 class MyException extends Exception{
2 public MyException(String msg){
3 super(msg);
4 }
5 }
6 public class ThrowsDemo {
7 public static void main(String args[]){
8 try{
9 throw new MyException("自定义异常");
10 }catch (Exception e){
11 System.out.println(e);
12 }
13 }
14 }

 用户根据自己日后需要,可以自己定义异常。。供自己调用。

posted @ 2012-03-11 19:36  谈笑风生膜法师  阅读(242)  评论(0编辑  收藏  举报