异常类:
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());
}
}
}
阅读(13305) | 评论(0) | 转发(0) |