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.
I think you should write your creation code as:
What's the advantage that way?
I suppose in general it's better to assign to a detachable type from an attached type. In this case there isn't an issue because it's a local. I'll switch it around.