Attachment in creation features with exceptions
This is a short template of what one can do when dealing with the perfect storm of complication using attached variables. This issue can arise when you need to attempt to release a resource, e.g. closing a file, that was created during a creation procedure, and you want the file to be attached in the enclosing class.
Say, for instance, in the below example we didn't use
the_file' and just used an attached file'. The rescue clause would not compile because it's not assured that the creation procedure for the file completed. We need an intermediary reference that is detached, to use in the rescue clause.
With this creation procedure you can be sure your file will always be closed and file is an attached member of the class.