注意:在finally中通常不写return,因为finally是必须会执行的,会将上面代码的返回值覆盖

  1. /**
  2. *
  3. * 演示finall的注意点
  4. */
  5. package Test15_Demo.Demo09;/*
  6. @create 2020--12--03--15:23
  7. */
  8. import java.io.FileWriter;
  9. import java.io.IOException;
  10. public class FinallyTest {
  11. public static void main(String[] args) {
  12. try {
  13. System.out.println(10 / 0);
  14. FileWriter fw = new FileWriter("");
  15. } catch (ArithmeticException ae) {
  16. } catch (IOException ie) {
  17. }finally {
  18. //注意:在finally中通常不写return,因为finally是必须会执行的,会将上面代码的返回值覆盖
  19. //return;
  20. }
  21. }
  22. }