Nov. 30, 2014
10:18 a.m.
Le 30/11/2014 11:06, Max Leske a écrit :
The code would look like this:
[ | file | file := StandardFileStream forceNewFileNamed: âfooâ. file nextPutAll: âbarâ ] ensure: [ file close ].
Why that is considered bad practice however, I canât tell.
This one would fail because file is a temp to the block (and not visible to the ensure block). Another problem is that, if you have a failure in forceNewFileNamed:, file is nil and the ensure: fail as well. This is how I interpret that rule. Thierry