本文主要是介绍Java,异常在方法内捕获处理后,后续方法依然能正常运行,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
运行时异常:
public int divideInt(int a, int b) {int c;try {c = a / b;} catch (RuntimeException e) {System.out.println("发生RuntimeException异常");c = 0;}System.out.println("catch之后");return c;}
main方法中:
System.out.println(test.divideInt(2, 0));System.out.println("----------");
输出:
发生RuntimeException异常
catch之后
0
----------
运行时异常:
public void f2() {int[] arr = new int[]{1, 2, 3};try {System.out.println(arr[4]);} catch (IndexOutOfBoundsException e) {System.out.println("发生IndexOutOfBoundsException异常");}System.out.println("catch之后");}
main方法中:
test.f2();System.out.println("----------");
输出:
发生IndexOutOfBoundsException异常
catch之后
----------
这篇关于Java,异常在方法内捕获处理后,后续方法依然能正常运行的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!