Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1449660
  • 博文数量: 254
  • 博客积分: 8696
  • 博客等级: 中将
  • 技术积分: 2961
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-03 16:46
文章分类

全部博文(254)

文章存档

2015年(4)

2014年(18)

2013年(16)

2012年(8)

2011年(25)

2010年(2)

2009年(74)

2008年(107)

分类: Java

2009-08-27 20:05:59

异常类:
public class DataException extends Exception
{
    String errorMessage;
 
    public DataException(String errorMessage)
    {
         this.errorMessage = errorMessage;
    }
 
    public String toString()
    {
         return errorMessage;
    }
 
    public String getMessage()
    {
         return errorMessage;
    }
}
 
测试:
public class Test
{
    public void justTest() throws DataException
    {
         int i = 0;
        
         if(i == 0)
             throw new DataException("i为0!");
    }
 
    public static void main(String[] args)
    {
        try
        {
            new Test().justText();
        }
        catch(DataException ex)
        {
            System.out.println(ex.getMessage());
        }
    }
}
 
阅读(13254) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~