From: Austin Ziegler Date: 2002-07-09T23:36:57+09:00 Subject: Re: for ... else ... end On Tue, 9 Jul 2002 18:10:01 +0900, Dirk Detering wrote: > Regarding the 'ensure' .... I think I did not understand if it is > a necessary part or only declarative sugar, as IMHO _every_ code > after the end is run in either case. > > So writing: > > f = File.open("testfile") > begin > # .. process > [...] > ensure > f.close > end > > or writing: > > f = File.open("testfile") > begin > # .. process > [...] > end > f.close They're not, though. It's entirely possible that the begin ... end block rethrows an exception or throws its own exception after receiving an exception. The ensure clause requires that the code within it be executed, even if the block is left because of a thrown, uncaught, or rethrown exception. -austin -- Austin Ziegler, austin@halostatue.ca on 2002.07.09 at 10.34.47