|
Boost Users : |
From: Jim.Hyslop (jim.hyslop_at_[hidden])
Date: 2002-09-18 14:26:20
Steve M. Robbins [mailto:steven.robbins_at_[hidden]] wrote:
> I use that technique to abort the Dijkstra shortest path
> search when I find my
> goal node. It works fine, as far as I can tell, but I'd be
> interested to
> learn if there is a better way.
It seems anti-idiomatic to me. Exceptions are intended to signify
exceptional circumstances that you would not normally expect to encounter
(at least according to one school of thought).
An exception tells me "Oops, something went wrong here" not "we succeeded,
here's the answer". Many of the exceptions I catch are called "oops":
try { /* ... */ }
catch (std::exception &oops)
{ /* ... */ }
One possible snag might be if your code interacts with someone else's code,
which will catch the exception and not pass it on to you. In the context
we're talking about, though, I don't see that as a significant problem.
An exception is certainly an easy way to abort the search, and since I don't
have an alternative to offer, I'll shut up now ;=)
-- Jim
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net