一个运行时异常如果被抛出。那么无论你处理不处理,之后的代码都不会被执行。 是如此么?而编译时异常,如果你捕获了并进行了处理,那么程序能够继续执行下去?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public static void main(String[] args){ try { int i = 9/0; }catch(ArithmeticException e) { e.printStackTrace(); } System.out.println("还在执行..."); } 如果在catch之前,还有其他的语句呢。//.....try{if(flag)throw RuntimeException("run wrong");System.out.println("after throw"); //run???}catch(RuntimeException e){ System.out.println(e.getMessage());} catch之前的语句不会执行,捕获异常后 finally语句块会执行 如果抛出一个运行时错误,finally也会执行么? //.....try{if(flag)throw RuntimeException("run wrong"); System.out.println("after throw"); //run???}finally{System.out.println("over");} final里边的语句无论如何都会执行 finally中写的语句是一定会执行的!无论try中是否有错,它都执行一次。所以把你必须要执行的代码放到finally块中。。 try的代码块在执行到出异常的时候不会再执行该代码块的其他代码;catch的代码块在出异常的时候才会执行,例如可以加一些日志之类的输出,方便故障的排除和定位;finally的代码块无论是不是出异常了都会执行的, 双向的冒泡法有点bug 求不是某字符串的正则表达式 Java Thread 电子书 中文 小虾米诚心求教 在myeclipse中可以运行,但是在eclipse中报错 Exception in thread "main" java.lang.NoClassDefFoundError的问题 java初学问题。 packaGe问题 jdk中事例程序中有后缀为.obj的,是什么文件呢? 有关继承中方法覆盖时访问控制的问题? MySQL语句执行问题,在线求助! Java中IO流问题--System.in
try {
int i = 9/0;
}catch(ArithmeticException e) {
e.printStackTrace();
}
System.out.println("还在执行...");
}
try{
if(flag)
throw RuntimeException("run wrong");System.out.println("after throw"); //run???
}
catch(RuntimeException e)
{
System.out.println(e.getMessage());
}
如果抛出一个运行时错误,finally也会执行么?
//.....
try{
if(flag)
throw RuntimeException("run wrong");
System.out.println("after throw"); //run???
}
finally
{
System.out.println("over");
}
finally中写的语句是一定会执行的!无论try中是否有错,它都执行一次。所以把你必须要执行的代码放到finally块中。。