您的位置:首页 > 其它

异常处理 学习笔记(二)

2013-11-14 16:58 309 查看
public class TestThrow
{
public static void main(String[] args)
{
try
{
throwChecked(-3);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
throwRuntime(3);
}
public static void throwChecked(int a) throws Exception
{
if(a>0)
{
throw new Exception("a的值大于0,不符合要求。");
}
}
public static void throwRuntime(int a)
{
if(a>0)
{
throw new RuntimeException("a的值大于0,不符合要求。");
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: