Salome HOME
Improve message in case of throw for end user.
[tools/medcoupling.git] / src / MEDLoader / MEDFileFieldOverView.cxx
index c3317e2954eb633f3da6e115d2324aa694ed6e81..105508eb1ea93fcedea87a968d5ef6ff8e0850be 100644 (file)
@@ -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
@@ -2037,7 +2038,6 @@ std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileField1TSStructItem::getGeo
 
 MEDFileField1TSStructItem MEDFileField1TSStructItem::BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt)
 {
-  TypeOfField atype;
   std::vector< MEDFileField1TSStructItem2 > anItems;
   //
   std::vector< std::vector<std::string> > pfls,locs;
@@ -2047,17 +2047,15 @@ MEDFileField1TSStructItem MEDFileField1TSStructItem::BuildItemFrom(const MEDFile
   std::size_t nbOfGeoTypes(geoTypes.size());
   if(nbOfGeoTypes==0)
     throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : not null by empty ref  !");
-  bool isFirst=true;
+  if(typesF[0].empty())
+    throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : internal error #1 bis !");
+  TypeOfField atype(typesF[0][0]);
   for(std::size_t i=0;i<nbOfGeoTypes;i++)
     {
       std::size_t sz=typesF[i].size();
       if(strtEnds[i].size()<1 || sz<1 || pfls[i].size()<1)
         throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : internal error #1 !");
       //
-      if(isFirst)
-        atype=typesF[i][0];
-      isFirst=false;
-      //
       for(std::size_t j=0;j<sz;j++)
         {
           if(atype==typesF[i][j])
@@ -2067,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;
 }
 
@@ -2300,8 +2306,17 @@ MEDFileFastCellSupportComparator::MEDFileFastCellSupportComparator(const MEDFile
   for(int i=0;i<nbPts;i++)
     {
       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> 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());
+        }
     }
 }