]> Creatis software - clitk.git/blobdiff - common/old/clitkIOCommon.cxx
cleanup / better handling of errors
[clitk.git] / common / old / clitkIOCommon.cxx
similarity index 94%
rename from common/clitkIOCommon.cxx
rename to common/old/clitkIOCommon.cxx
index 16ec36127d677b7b3cf377d0b32f007666dddf17..be69d374edfa5caad8f08db2a7b1c689a99d37f4 100644 (file)
@@ -28,7 +28,8 @@ PURPOSE.  See the above copyright notices for more information.
    =================================================*/
 
 // clitk include
-#include "clitkIOCommon.h"
+#include "clitkImageCommon.h"
+#include <cstdlib>
 
 //====================================================================
 // Open a file for reading
@@ -66,10 +67,17 @@ gdcm::File * clitk::readDicomHeader(const std::string & filename,
 //====================================================================
 
 //====================================================================
-itk::ImageIOBase::Pointer clitk::readImageHeader(const std::string & filename) {
+itk::ImageIOBase::Pointer clitk::readImageHeader(const std::string & filename, bool exit_on_error) {
   itk::ImageIOBase::Pointer reader =
     itk::ImageIOFactory::CreateImageIO(filename.c_str(), itk::ImageIOFactory::ReadMode);
-  if (!reader) return NULL;
+  if (!reader) 
+      if (exit_on_error) //default behavior for tools who don't handle the problem
+      {
+          std::cerr "Error reading file " << filename << ", exiting immediately" << std::endl;
+          std::exit(-1);
+      }
+      else
+          return NULL;
   reader->SetFileName(filename);
   reader->ReadImageInformation();
   return reader;