From: Michal Suchanek Date: 2009-02-22T00:38:16+09:00 Subject: [ruby-core:22312] Re: [Feature #1122] request for: Object#try On 21/02/2009, Roger Pack wrote: ... > > > The other thing I occasionally do and which could be more streamlined > > looks like this: > > > > here fd of a pipe might be already closed but it may not > > > > fd.close rescue nil # hopefully prevents zombie hordes > > > > assume Object#quiet returns an object that does not raise an exception: > > > > fd.quiet.close # hopefully prevent zombie hordes > > > That is interesting [but how does it know which exception to > swallow--assume StandardError? what if the exception raised isn't > quite the expected one? ] :) > In this case I don't really care. I want to close the pipe if possible, and ignore the case when it cannot be closed because it is already invalid. However, there are cases when the semantics would not be clear. Does it catch any exception or only some subclass(es)? Does it catch exceptions originating in that object or also ones originating on other objects that might be invoked by the "quiet" object? I am not sure what would be the best option. Perhaps this tool is not good fit for the ambiguous cases although the behaviour should still be defined somehow. Thanks Michal