Check status of object finalization (deallocation)

Suppose I have an object A with a FINAL routine that calls some delegate deallocation routines which can return errors. If I do a DEALLOCATE(A), that FINAL routine is called. How would I check that error status or, to put it differently: how could I change the value of the optional STAT variable in DEALLOCATE(A, STAT=somestat) so I can query it and issue an appropriate error message, if at all?

You can’t. There aren’t “hooks” into the language’s intrinsic statements in quite that way. Trying to propagate errors out of final subroutines is probably not going to be a very elegant design. Sometimes when the use of final subroutines seems like it might be a good fit at first, I still end up using a more explicit API to have more control over exactly when the cleanup code is called.

1 Like