From: jean-pierre roux Date: Fri, 19 Jun 2009 15:51:44 +0000 (+0000) Subject: Throw and catch exception *everywhere* (hope it's enough!) X-Git-Tag: CREATOOLS.2-0-3~41 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=11a9650af17244f38034d70edf3c638274c8a01c;p=creaBruker.git Throw and catch exception *everywhere* (hope it's enough!) --- diff --git a/appli/testBruker2Dicom/testBruker2Dicom.cxx b/appli/testBruker2Dicom/testBruker2Dicom.cxx index a9a6c32..ba04036 100644 --- a/appli/testBruker2Dicom/testBruker2Dicom.cxx +++ b/appli/testBruker2Dicom/testBruker2Dicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: testBruker2Dicom.cxx,v $ Language: C++ - Date: $Date: 2009/05/27 10:43:07 $ - Version: $Revision: 1.4 $ + Date: $Date: 2009/06/19 15:51:44 $ + Version: $Revision: 1.5 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -31,6 +31,7 @@ #include "gdcmArgMgr.h" #include "bruker2dicom.h" +#include "brukerexception.h" // =================================================================================================== /** @@ -152,7 +153,7 @@ int main(int argc, char *argv[]) // b2d.day : unused ... b2d.day = am->ArgMgrGetString("day", "You_forget_the_Day"); - + delete am; // we don't need Argument Manager any longer // ----------- End Arguments Manager --------- @@ -178,9 +179,12 @@ int main(int argc, char *argv[]) } */ + catch (BrukerHopelessException &e) + { + std::cout << "And Hopless Exception was thrown (" << e.what() << ") " << std::endl; + } - delete am; // we don't need Argument Manager any longer } diff --git a/lib/src1/bruker2dicom.cxx b/lib/src1/bruker2dicom.cxx index aca5d1c..eac2702 100644 --- a/lib/src1/bruker2dicom.cxx +++ b/lib/src1/bruker2dicom.cxx @@ -181,8 +181,14 @@ bool Bruker2Dicom::Execute() if (verbose) printf ("outputDirName [%s]\n", outputDirName); - - DealWithNiveau1(*it, outputDirName); + try { + DealWithNiveau1(*it, outputDirName); + } + catch (BrukerHopelessException &e) + { + std::cout << "And Exception was thrown in DealWithNiveau1 (" << e.what() << ") " << std::endl; + continue; + } } } // end of : for (GDCM_NAME_SPACE::DirListType::iterator it } @@ -268,8 +274,10 @@ void Bruker2Dicom::DealWithNiveau1(std::string level1Directory, std::string curr canOpen = br_method.LoadFile(strMethod); if (!canOpen) { - std::cout << "Hopeless! neither 'method' nor 'imnd' found" << std::endl; - throw ( BrukerHopelessException ("Hopeless! neither 'method' nor 'imnd' found ")); + std::cout << "Hopeless! neither 'method' nor 'imnd' found in [" + << level1Directory << "]; we skip it!" << std::endl; + continue; + //throw ( BrukerHopelessException ("Hopeless! neither 'method' nor 'imnd' found ")); //exit(0); /// \TODO throw an exception ! } } @@ -288,7 +296,14 @@ void Bruker2Dicom::DealWithNiveau1(std::string level1Directory, std::string curr ##$PVM_SPackArrNSlices=( 2 ) 7 1 */ - DealWithNiveau2(*it,outputDirName ); + try { + DealWithNiveau2(*it,outputDirName ); + } + catch (BrukerHopelessException &e) + { + std::cout << "And Exception was thrown in DealWithNiveau2 (" << e.what() << ") " << std::endl; + continue; + } } } } @@ -379,8 +394,16 @@ void Bruker2Dicom::DealWithNiveau2(std::string level2Directory, std::string curr GDCM_NAME_SPACE::GDCM_FILESEPARATOR, GDCM_NAME_SPACE::Util::GetName(*it).c_str(), str_isa_func_name.c_str()); - } - DealWithNiveau3(*it, outputDirName); + } + try { + DealWithNiveau3(*it, outputDirName); + } + catch (BrukerHopelessException &e) + { + std::cout << "And Exception was thrown in DealWithNiveau3 (" << e.what() << "); " + << " We skip [" << level2Directory << "]" << std::endl; + continue; + } } } } @@ -585,8 +608,10 @@ void Bruker2Dicom::DealWithNiveau3(std::string level3Directory, std::string curr } catch (BrukerInitException& e) { - std::cout << "Exception " << e.what() << std::endl; - return; + std::cout << "an Exception was throw in CreateImageSet ( ); " << e.what() + << "catched in DealWithNiveau3" << std::endl; + //return; + throw (e); } serieNumber++; @@ -860,7 +885,7 @@ void Bruker2Dicom::dealWithCarto(GDCM_NAME_SPACE::DirListType &fileNames, int NX fp = fopen ( (*it).c_str(), "rb"); if (!fp){ std::cout << "Cannot open [" << *it << "] for reading" << std::endl; - + throw ( BrukerHopelessException ("Level 1 Unable to open 'carto' file ")); } fread(buffer_carto, NX*NY*sizeof(double), nbSlices, fp); @@ -970,8 +995,8 @@ bool Bruker2Dicom::CreateDirectory(std::string OutputDirName) { if (verbose) std::cout << "KO : not a dir : [" << OutputDirName << "] (creation failure ?)" << std::endl; - return 0; - /// \todo : THROW AN EXCEPTION + //return 0; + throw ( BrukerHopelessException ("Level 1 output directory creation failure ")); } else { @@ -1314,10 +1339,13 @@ std::cout << "charImageOrientation " << fileH->SetImageData((uint8_t *)tabPixels, X*Y*nbFrames*pixelSize); fileH->SetWriteModeToRaw(); fileH->SetWriteTypeToDcmExplVR(); - if( !fileH->Write(dcmImageName)) + if( !fileH->Write(dcmImageName)) { std::cout << "Failed for [" << dcmImageName << "]\n" - << " File is unwrittable" << std::endl; - + << " File is unwrittable" << std::endl; + file->Delete(); + fileH->Delete(); + throw ( BrukerHopelessException ("Level 1 Unable to write Dicom file ")); + } if (verbose) file->Print();