Re: Which STL algorithm?
From: Pete Becker (petebecker_at_acm.org)
Date: 02/24/05
- Next message: Kevin Frey: "Re: auto_ptr pass-by-value to a method results in erroneous object destruction"
- Previous message: Doug Harrison [MVP]: "Re: Which STL algorithm?"
- In reply to: Doug Harrison [MVP]: "Re: Which STL algorithm?"
- Next in thread: Doug Harrison [MVP]: "Re: Which STL algorithm?"
- Reply: Doug Harrison [MVP]: "Re: Which STL algorithm?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 24 Feb 2005 14:13:40 -0500
Doug Harrison [MVP] wrote:
> Pete Becker wrote:
>
>
>>Doug Harrison [MVP] wrote:
>>
>>
>>>Is there any prohibition on an output iterator throwing an exception? I
>>>don't think so, and if not, you could write a set_any_in_common function
>>>that catches this exception and terminates as soon as possible. This might
>>>be appropriate for algorithms more complicated than the one Pete posted in
>>>his message.
>>
>>No, it would not be appropriate. Exceptions aren't for normal returns.
>>They're for exceptional events. They create hidden execution paths, and
>>that makes understanding the code hard. Not to mention the performance hit.
>
>
> In general I agree with that. However, provided there is no prohibition on
> the output iterator throwing exceptions, it would be appropriate to do just
> that to adapt an algorithm too complex or lengthy to duplicate, or absent
> the source code, recreate entirely on your own. Consider:
>
> bool f()
> {
> try
> {
> lengthy_f_that_provides_no_early_return(Iter_that_throws());
> }
> catch (the_exception_type)
> {
> return true;
> }
> return false;
> }
>
> As lengthy_f is a black box that doesn't prohibit the iterator from
> throwing, the "hidden execution path" argument doesn't even apply to the
> person writing f. The performance hit argument may not apply, given that the
> poor performance of the algorithm that doesn't terminate ASAP is the whole
> reason for looking for an alternative. That's something that can only be
> determined empirically. But if duplicating the algorithm as you did is
> significantly harder than writing the Iter_that_throws class, looking for a
> way to work with what you've got surely is the way to go, at least until
> proven otherwise.
>
This is the first step down the slippery slope towards Java-style use of
exceptions. Don't do it.
-- Pete Becker Dinkumware, Ltd. (http://www.dinkumware.com)
- Next message: Kevin Frey: "Re: auto_ptr pass-by-value to a method results in erroneous object destruction"
- Previous message: Doug Harrison [MVP]: "Re: Which STL algorithm?"
- In reply to: Doug Harrison [MVP]: "Re: Which STL algorithm?"
- Next in thread: Doug Harrison [MVP]: "Re: Which STL algorithm?"
- Reply: Doug Harrison [MVP]: "Re: Which STL algorithm?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|