in reply to Re: Is there a way to know why the DESTROY method was invoked?
in thread Is there a way to know why the DESTROY method was invoked?

Thank you for your reply
Yesterday I realized that I had not called the close method for an open file. I would like to trap this situation when the file handle goes out-of-scope so that I can make sure that the close is in place.
A side affect of implementing the DESTROY method is that the method complains when the interpreter is stopped because the die function was invoked.
I would like to know why the reference is going out-of-scope in the DESTROY method so that I can elect to report the message or just let it go.
  • Comment on Re^2: Is there a way to know why the DESTROY method was invoked?

Replies are listed 'Best First'.
Re^3: Is there a way to know why the DESTROY method was invoked?
by ikegami (Patriarch) on Feb 18, 2010 at 18:24 UTC

    close isn't complaining because an exception has been thrown. Why is close actually complaining? (i.e. What error are you getting?) That's the problem you actually need to fix.

    By the way, if you don't check if close returned an error, you don't need to call it. The file or file object will close itself if necessary.