From: Anthony Geay Date: Fri, 30 Jan 2015 16:10:03 +0000 (+0100) Subject: Improve message in case of throw for end user. X-Git-Tag: V7_6_0a1~15 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c483b6a8c2165f64d507dbab661c933a605097e9;p=tools%2Fmedcoupling.git Improve message in case of throw for end user. --- diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx index 22a30a28a..bde0a8efe 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -159,6 +159,21 @@ TypeOfField MEDCouplingFieldDiscretization::GetTypeOfFieldFromStringRepr(const s throw INTERP_KERNEL::Exception("Representation does not match with any field discretization !"); } +std::string MEDCouplingFieldDiscretization::GetTypeOfFieldRepr(TypeOfField type) +{ + if(type==MEDCouplingFieldDiscretizationP0::TYPE) + return MEDCouplingFieldDiscretizationP0::REPR; + if(type==MEDCouplingFieldDiscretizationP1::TYPE) + return MEDCouplingFieldDiscretizationP1::REPR; + if(type==MEDCouplingFieldDiscretizationGauss::TYPE) + return MEDCouplingFieldDiscretizationGauss::REPR; + if(type==MEDCouplingFieldDiscretizationGaussNE::TYPE) + return MEDCouplingFieldDiscretizationGaussNE::REPR; + if(type==MEDCouplingFieldDiscretizationKriging::TYPE) + return MEDCouplingFieldDiscretizationKriging::REPR; + throw INTERP_KERNEL::Exception("GetTypeOfFieldRepr : Representation does not match with any field discretization !"); +} + bool MEDCouplingFieldDiscretization::isEqual(const MEDCouplingFieldDiscretization *other, double eps) const { std::string reason; diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx index 17fb76c65..fc6238711 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx @@ -50,6 +50,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; MEDCOUPLING_EXPORT std::vector getDirectChildrenWithNull() const; MEDCOUPLING_EXPORT static TypeOfField GetTypeOfFieldFromStringRepr(const std::string& repr); + MEDCOUPLING_EXPORT static std::string GetTypeOfFieldRepr(TypeOfField type); MEDCOUPLING_EXPORT virtual TypeOfField getEnum() const = 0; MEDCOUPLING_EXPORT virtual bool isEqual(const MEDCouplingFieldDiscretization *other, double eps) const; MEDCOUPLING_EXPORT virtual bool isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const = 0; diff --git a/src/MEDLoader/MEDFileFieldOverView.cxx b/src/MEDLoader/MEDFileFieldOverView.cxx index 9d5c0a435..105508eb1 100644 --- a/src/MEDLoader/MEDFileFieldOverView.cxx +++ b/src/MEDLoader/MEDFileFieldOverView.cxx @@ -22,6 +22,7 @@ #include "MEDFileField.hxx" #include "MEDFileMesh.hxx" +#include "MEDCouplingFieldDiscretization.hxx" #include "CellModel.hxx" using namespace ParaMEDMEM; @@ -1664,7 +1665,7 @@ void MEDFileField1TSStructItem2::checkInRange(int nbOfEntity, int nip, const MED if(_pfl->getName().empty()) { if(nbOfEntity!=(_start_end.second-_start_end.first)/nip) - throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Mismatch between number of entities and size of node field !"); + throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Mismatch between number of entities and size of field !"); return ; } else @@ -2064,7 +2065,15 @@ MEDFileField1TSStructItem MEDFileField1TSStructItem::BuildItemFrom(const MEDFile } } MEDFileField1TSStructItem ret(atype,anItems); - ret.checkWithMeshStruct(meshSt,ref); + try + { + ret.checkWithMeshStruct(meshSt,ref); + } + catch(INTERP_KERNEL::Exception& e) + { + std::ostringstream oss; oss << e.what() << " (" << MEDCouplingFieldDiscretization::GetTypeOfFieldRepr(ret.getType()) << ")"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } return ret; } @@ -2297,8 +2306,17 @@ MEDFileFastCellSupportComparator::MEDFileFastCellSupportComparator(const MEDFile for(int i=0;i elt=ref->getTimeStepAtPos(i); - _f1ts_cmps[i]=MEDFileField1TSStruct::New(elt,_mesh_comp); - _f1ts_cmps[i]->checkWithMeshStruct(_mesh_comp,elt); + try + { + _f1ts_cmps[i]=MEDFileField1TSStruct::New(elt,_mesh_comp); + _f1ts_cmps[i]->checkWithMeshStruct(_mesh_comp,elt); + } + catch(INTERP_KERNEL::Exception& e) + { + std::ostringstream oss; oss << "Problem in field with name \"" << ref->getName() << "\"" << std::endl; + oss << "More Details : " << e.what(); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } } }