method finalize and exceptions

后端 未结 3 727
梦谈多话
梦谈多话 2021-01-22 09:56

I don\'t understand very well when an exception is ignored by the GC when it reclaims from the memory an object.

If I have a try/catch into a finalize metho

3条回答
  •  半阙折子戏
    2021-01-22 10:27

    the finalize method is run by the finalizer thread. if you throw exception, the finalizer will ignore it (swallow it). Otherwise, the finalizer thread would die. This applies to exceptions that are thrown and not caught by your code (inside finalize()). If you catch the exception, it is business as usual.

提交回复
热议问题