[Insight-developers] exception swallowed by ImageFileReader::GenerateOutputInformation()

Luis Ibanez luis.ibanez at kitware.com
Mon Jul 9 19:14:44 EDT 2007


Hi Steve,

       Thanks for pointing this out.

You are right in that exception shouldn't be
caught just to silence them. That will defeat
the purpose of the exception in the first place.


Note however that in this case, the exception is not
simply "swallowed". Instead, the actual message is
carried along to line: 125, and then used to compose
a more detailed exception message in lines 131-141.


The exception is finally rethrown in lines 143-144
as a more specific type of Exception:

           "ImageFileReaderException"


Please let us know if you find any other suspicious code.


     Thanks


       Luis


--------------------------
Steve M. Robbins wrote:
> Hi,
> 
> I'm perusing the code of ImageIO and friends.  The following snippet
> caught my eye:
> 
> template <class TOutputImage, class ConvertPixelTraits>
> void ImageFileReader<TOutputImage, ConvertPixelTraits>::GenerateOutputInformation(void)
> {
>   [... elided ...]
>   
>   // Test if the file exist and if it can be open.
>   // and exception will be thrown otherwise.
>   //
>   try
>     {
>     m_ExceptionMessage = "";
>     this->TestFileExistanceAndReadability();
>     }
>   catch(itk::ExceptionObject &err)
>     {
>     m_ExceptionMessage = err.GetDescription();
>     }
> 
>   [...]
> 
> The method goes on to read the image information and set up the
> output.
> 
> I'm a little concerned that the exception from
> TestFileExistanceAndReadability() is swallowed.
> Wouldn't it make sense to simply let the exception
> propagate?
> 
> -Steve
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk.org
> http://www.itk.org/mailman/listinfo/insight-developers


More information about the Insight-developers mailing list