From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-01-26 11:01:03


From: "Thomas Maeder" <maeder_at_[hidden]>
> Am 2002.01.26 12:53 schrieb(en) Peter Dimov:
> > > But in general, the success of fclose() should be checked. Can
> > > shared_ptr be used then?
> >
> > Should it?
>
> Yes (in general). It's an operation that can fail. There are programs
> that have to behave differently if fclose() succeeds from when it fails.

Would you please provide a specific example or two. I've trouble following
your reasoning.

In general, the problem lies not in shared_ptr, but in the destructor
function that can fail. This function should be split in two, a function
that can fail (but does not destroy) and a destructor that never fails. This
is, of course, not possible in the general case and the usual way to "solve"
the problem is to ignore the failure, which - surprisingly - works pretty
well in practice.

If we return to our fclose example, the "can fail but does not destroy"
mechanism is fflush.