我想知道怎样的错误可以在java中被捕获,但允许程序继续运行。Java是否支持异常后恢复程序执行?
这里是我的例子:
public class test1 {
public static void main(String[] args) {
String str = new String("abcdefghij");
try {
System.out.println(str.charAt(0));
System.out.println(str.charAt(9));
System.out.println(str.charAt(10));
System.out.println("is it still running");
} catch (Exception e) {
System.out.println("the index is out of bounds");
}
}
}
打印以下内容:
a
j
the index is out of bounds
但之后引发错误我想代码继续运行,因此,这是印刷:
a
j
the index is out of bounds
is it still running
在此先感谢
这是我希望避免,很好哦,感谢有关Java :) – java 2010-12-11 04:52:30
@java针对特定问题的信息种类-的,它(另)一个问题可能是有益的。另外,对发现SO和大房间的整体吨知识的不同(有时更好)接近给定的问题,一组特定的约束条件(例如,Java)内。 – 2010-12-11 07:02:52