Final version of the method and exceptions

I do not understand very well when an exception is ignored by the GC, when it restores an object from memory.

If I have try/catcha finalize method in it, I see that it always executes ... so what happens when an exception is not thrown?

Thank.

+2
source share
3 answers

the method is finalizelaunched by the finalizer thread. if you select an exception, the finalizer will ignore it (swallow). Otherwise, the stream of the finalizer will die. This applies to exceptions that are thrown and not caught in your code (internally finalize()). If you catch an exception, this is common.

+4
source

, , finalize, . - .

+2

Two existing answers say that the finalizer will ignore any uncaught exceptions. This seems to contradict the answer here: An exception is in the finalize method , which appears to have the correct JSL reference. It says that uncaught exceptions will interrupt the completion of the corresponding object (possibly a resource leak), but the finalizer itself will continue to complete the other objects. This is consistent with empirical results.

+2
source

All Articles