image.png

    1. package test;
    2. public class Main {
    3. public static void main(String[] args) {
    4. try {
    5. ReturnExceptionDemo.methodA();
    6. } catch (Exception e) {
    7. System.out.println(e.getMessage());
    8. }
    9. ReturnExceptionDemo.methodB();
    10. }
    11. }
    12. class ReturnExceptionDemo {
    13. static void methodA() {
    14. try {
    15. System.out.println("进入方法A");
    16. throw new RuntimeException("制造异常");
    17. } finally {
    18. System.out.println("用A方法的finally");
    19. }
    20. }
    21. static void methodB() {
    22. try {
    23. System.out.println("进入方法B");
    24. return;
    25. } finally {
    26. System.out.println("调用B方法的finally");
    27. }
    28. }
    29. }

    image.png