[Insight-developers] Infinite loops

Brad King brad.king@kitware.com
Mon, 23 Apr 2001 11:02:28 -0400 (EDT)


Luis,

> One possible source of error is that inside the Mapper we are using
> exceptions to report when a point is outside the range of the target
> image, the number of these exceptions can be quite large (as high as
> the number of pixels in the image), and it is not clear how each
> compiler manage this high flow of exceptions.
........
> In that case we should replace the code:
> try { value =  mapper.GetValue( point ); }
> catch() { value = 0; }
> for a "contract" style code with a preconditions like:
> if(  mapper.IsPointInside( point ) )  { value = mapper.GetValue(); }
> else { value = 0; }

I've seen several discussions on other lists about using exceptions to
control program flow.  Most of them resulted in a decision to use
exceptions only when unexpected conditions occur.  If an algorithm
routinely looks at points that might be outside the target image, then the
"if" check should be used, not an exception.  Exception handling is not
going to be as fast as an explicit test, but there is a more theoretical
reason, too.  Testing if a point is outside the target image is part of
the algorithm, so it should have its own test as part of the algorithm's
implementation.

-Brad