第一个格式:
try
{
}
catch()
{
}
第二个格式:
try
{
}
catch()
{
}
finally
{
}
第三个格式:
try
{
}
finally
{
}
//记住一点:catch是用于处理异常,如果没有catch就代表异常没有被处理过如果该异常是检测时异常,那么必须声明。
class Demo
{
public void method()
{
try
{
throw new Exception();
}
catch(Exception e)
{
throw e;
}
}
}
class ExceptionDemo6
{
public static void main(String[] args)
{
System.out.println("Holle World!");
}
}
java面向对象-异常声明的几种格式
最新推荐文章于 2024-04-29 09:28:29 发布