]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
Check mesh size before export
authoreap <eap@opencascade.com>
Fri, 12 Mar 2021 16:29:02 +0000 (19:29 +0300)
committereap <eap@opencascade.com>
Fri, 12 Mar 2021 16:29:02 +0000 (19:29 +0300)
src/Driver/Driver_Mesh.h
src/DriverCGNS/DriverCGNS_Write.cxx
src/DriverGMF/DriverGMF_Write.cxx
src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx
src/DriverUNV/DriverUNV_W_SMDS_Mesh.cxx
src/SMESH/SMESH_Mesh.cxx
src/SMESH/SMESH_Mesh.hxx
src/SMESHGUI/SMESHGUI.cxx
src/SMESHUtils/SMESH_TryCatch.hxx
src/SMESH_I/SMESH_Mesh_i.cxx

index bd6a714065390919aff1b4eea5d91de3bc4552d7..30ab4e286726bee23b96fe26eed486d329fe55e9 100644 (file)
@@ -28,6 +28,7 @@
 #define _INCLUDE_DRIVER_MESH
 
 #include "SMESH_ComputeError.hxx"
+#include "SMDS_Mesh.hxx"
 
 #include <string>
 #include <vector>
@@ -50,12 +51,13 @@ class MESHDRIVER_EXPORT Driver_Mesh
 
   enum Status {
     DRS_OK,
-    DRS_EMPTY,          // a file contains no mesh with the given name
-    DRS_WARN_RENUMBER,  // a file has overlapped ranges of element numbers,
-                        // so the numbers from the file are ignored
-    DRS_WARN_SKIP_ELEM, // some elements were skipped due to incorrect file data
+    DRS_EMPTY,           // a file contains no mesh with the given name
+    DRS_WARN_RENUMBER,   // a file has overlapped ranges of element numbers,
+                         // so the numbers from the file are ignored
+    DRS_WARN_SKIP_ELEM,  // some elements were skipped due to incorrect file data
     DRS_WARN_DESCENDING, // some elements were skipped due to descending connectivity
-    DRS_FAIL            // general failure (exception etc.)
+    DRS_FAIL,            // general failure (exception etc.)
+    DRS_TOO_LARGE_MESH   // mesh is too large for export
   };
 
   void                SetMeshId(int theMeshId);
@@ -70,6 +72,22 @@ class MESHDRIVER_EXPORT Driver_Mesh
 
   virtual SMESH_ComputeErrorPtr GetError();
 
+  //virtual bool CanExportMesh() const { return false; } //= 0;
+
+  // check if a mesh is too large to export it using IDTYPE;
+  // check either max ID or number of elements
+  template< typename IDTYPE >
+    static bool IsMeshTooLarge( const SMDS_Mesh* mesh, bool checkIDs )
+  {
+    if ( sizeof( IDTYPE ) < sizeof( smIdType ))
+    {
+      const smIdType maxNB = std::numeric_limits< IDTYPE >::max();
+      return (( checkIDs ? mesh->MaxNodeID()    : mesh->NbNodes() )  > maxNB ||
+              ( checkIDs ? mesh->MaxElementID() : mesh->NbElements() > maxNB ));
+    }
+    return false;
+  }
+
  protected:
   std::string myFile;
   std::string myMeshName;
index bd6bcff2f17f899066969f95180523e944760884..0643273cb61733042cd22c00c283db33c3b4d186 100644 (file)
@@ -248,6 +248,9 @@ Driver_Mesh::Status DriverCGNS_Write::Perform()
   if ( !myMesh || myMesh->GetMeshInfo().NbElements() < 1 )
     return addMessage( !myMesh ? "NULL mesh" : "Empty mesh (no elements)", /*fatal = */true );
 
+  if ( Driver_Mesh::IsMeshTooLarge< cgsize_t >( myMesh, /*checkIDs =*/ false))
+    return DRS_TOO_LARGE_MESH;
+
   // open the file
   if ( cg_open(myFile.c_str(), CG_MODE_MODIFY, &_fn) != CG_OK &&
        cg_open(myFile.c_str(), CG_MODE_WRITE,  &_fn) != CG_OK )
@@ -282,7 +285,9 @@ Driver_Mesh::Status DriverCGNS_Write::Perform()
   else if ( meshDim == 2 )
     nbCells = myMesh->NbFaces();
 
-  cgsize_t size[9] = { myMesh->NbNodes(), nbCells, /*NBoundVertex=*/0, 0,0,0,0,0,0 };
+  cgsize_t size[9] = { FromIdType<cgsize_t>( myMesh->NbNodes() ),
+                       FromIdType<cgsize_t>( nbCells ),
+                       /*NBoundVertex=*/0, 0,0,0,0,0,0 };
   int iZone;
   if ( cg_zone_write( _fn, iBase, "SMESH_Mesh", size,
                       CGNS_ENUMV( Unstructured ), &iZone) != CG_OK )
index 69388298aad4496a9e73a61c5dee55dc99491eb3..ceaad21974f78b9cec8b678c04ef55b767c424d0 100644 (file)
@@ -100,6 +100,9 @@ Driver_Mesh::Status DriverGMF_Write::Perform()
 {
   Kernel_Utils::Localizer loc;
 
+  if ( Driver_Mesh::IsMeshTooLarge< int >( myMesh, /*checkIDs =*/ false))
+    return DRS_TOO_LARGE_MESH;
+
   const int dim = 3, version = sizeof(double) < 8 ? 1 : 2;
 
   int meshID = GmfOpenMesh( myFile.c_str(), GmfWrite, version, dim );
index 375572dd50629e1c145d7579da2ad3b32590b39a..bd5e48f4704ee4e84d6df5b4ff784119c5c02b4c 100644 (file)
@@ -343,12 +343,21 @@ namespace
   }
 }
 
+//================================================================================
+/*!
+ * \brief Write my mesh
+ */
+//================================================================================
+
 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
 {
   Status aResult = DRS_OK;
   try {
     //MESSAGE("Perform - myFile : "<<myFile);
 
+    if ( Driver_Mesh::IsMeshTooLarge< TInt >( myMesh, /*checkIDs =*/ true ))
+      return DRS_TOO_LARGE_MESH;
+
     // Creating the MED mesh for corresponding SMDS structure
     //-------------------------------------------------------
     string aMeshName;
@@ -559,7 +568,7 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
         aTCoordSlice[2] = 0.;
 
       // node number
-      int aNodeID = aCoordHelperPtr->GetID();
+      TInt aNodeID = FromIdType<TInt>( aCoordHelperPtr->GetID() );
       aNodeInfo->SetElemNum( iNode, aNodeID );
 #ifdef _EDF_NODE_IDS_
       aNodeIdMap.insert( aNodeIdMap.end(), make_pair( aNodeID, iNode+1 ));
index 95da345254486b01277996726c8a477be9066b98..da3381285d67c6268b4405d01e85afb3937602ca 100644 (file)
@@ -45,6 +45,10 @@ Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform()
 {
   Kernel_Utils::Localizer loc;
   Status aResult = DRS_OK;
+
+  if ( Driver_Mesh::IsMeshTooLarge< int >( myMesh, /*checkIDs =*/ false))
+    return DRS_TOO_LARGE_MESH;
+
 #if defined(WIN32) && defined(UNICODE)
   std::wstring aFile = Kernel_Utils::utf8_decode_s(myFile);
   std::ofstream out_stream(aFile.c_str());
@@ -256,11 +260,11 @@ Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform()
       EXCEPTION(runtime_error,"ERROR: Output file not good.");
   }
   catch(const std::exception& exc){
-    INFOS("Follow exception was cought:\n\t"<<exc.what());
+    INFOS("Follow exception was caught:\n\t"<<exc.what());
     throw;
   }
   catch(...){
-    INFOS("Unknown exception was cought !!!");
+    INFOS("Unknown exception was caught !!!");
     throw;
   }
   return aResult;
index 5b626e6f24656149ce2e57d7d8cd974f433f39d5..0941689684e4db1ca6d956361971a656f17600cb 100644 (file)
@@ -1428,6 +1428,8 @@ void SMESH_Mesh::ExportMED(const char *        file,
                            bool                theAllElemsToGroup)
 {
   MESSAGE("MED_VERSION:"<< theVersion);
+
+  Driver_Mesh::Status status;
   SMESH_TRY;
 
   DriverMED_W_SMESHDS_Mesh myWriter;
@@ -1482,9 +1484,12 @@ void SMESH_Mesh::ExportMED(const char *        file,
     }
   }
   // Perform export
-  myWriter.Perform();
+  status = myWriter.Perform();
 
   SMESH_CATCH( SMESH::throwSalomeEx );
+
+  if ( status == Driver_Mesh::DRS_TOO_LARGE_MESH )
+    throw TooLargeForExport("MED");
 }
 
 //================================================================================
@@ -1509,9 +1514,15 @@ void SMESH_Mesh::ExportSAUV(const char *file,
   cmd += "from medutilities import my_remove ; my_remove(r'" + medfilename + "')";
   cmd += "\"";
   system(cmd.c_str());
-  ExportMED(medfilename.c_str(), theMeshName, theAutoGroups, /*minor=*/-1,
-            /*meshPart=*/NULL, /*theAutoDimension=*/false, /*theAddODOnVertices=*/false,
-            /*zTol=*/-1, /*theAllElemsToGroup=*/true ); // theAllElemsToGroup is for PAL0023413
+  try {
+    ExportMED(medfilename.c_str(), theMeshName, theAutoGroups, /*minor=*/-1,
+              /*meshPart=*/NULL, /*theAutoDimension=*/false, /*theAddODOnVertices=*/false,
+              /*zTol=*/-1, /*theAllElemsToGroup=*/true ); // theAllElemsToGroup is for PAL0023413
+  }
+  catch ( TooLargeForExport )
+  {
+    throw TooLargeForExport("SAUV");
+  }
 #ifdef WIN32
   cmd = "%PYTHONBIN% ";
 #else
@@ -1541,12 +1552,19 @@ void SMESH_Mesh::ExportSAUV(const char *file,
 void SMESH_Mesh::ExportDAT(const char *        file,
                            const SMESHDS_Mesh* meshPart)
 {
-  Unexpect aCatch(SalomeException);
+  Driver_Mesh::Status status;
+  SMESH_TRY;
+
   DriverDAT_W_SMDS_Mesh myWriter;
   myWriter.SetFile( file );
   myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
   myWriter.SetMeshId(_id);
-  myWriter.Perform();
+  status = myWriter.Perform();
+
+  SMESH_CATCH( SMESH::throwSalomeEx );
+
+  if ( status == Driver_Mesh::DRS_TOO_LARGE_MESH )
+    throw TooLargeForExport("DAT");
 }
 
 //================================================================================
@@ -1558,7 +1576,9 @@ void SMESH_Mesh::ExportDAT(const char *        file,
 void SMESH_Mesh::ExportUNV(const char *        file,
                            const SMESHDS_Mesh* meshPart)
 {
-  Unexpect aCatch(SalomeException);
+  Driver_Mesh::Status status;
+
+  SMESH_TRY;
   DriverUNV_W_SMDS_Mesh myWriter;
   myWriter.SetFile( file );
   myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
@@ -1579,7 +1599,12 @@ void SMESH_Mesh::ExportUNV(const char *        file,
       }
     }
   }
-  myWriter.Perform();
+  status = myWriter.Perform();
+
+  SMESH_CATCH( SMESH::throwSalomeEx );
+
+  if ( status == Driver_Mesh::DRS_TOO_LARGE_MESH )
+    throw TooLargeForExport("UNV");
 }
 
 //================================================================================
@@ -1593,14 +1618,21 @@ void SMESH_Mesh::ExportSTL(const char *        file,
                            const char *        name,
                            const SMESHDS_Mesh* meshPart)
 {
-  Unexpect aCatch(SalomeException);
+  Driver_Mesh::Status status;
+  SMESH_TRY;
+
   DriverSTL_W_SMDS_Mesh myWriter;
   myWriter.SetFile( file );
   myWriter.SetIsAscii( isascii );
   myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS);
   myWriter.SetMeshId(_id);
   if ( name ) myWriter.SetName( name );
-  myWriter.Perform();
+  status = myWriter.Perform();
+
+  SMESH_CATCH( SMESH::throwSalomeEx );
+
+  if ( status == Driver_Mesh::DRS_TOO_LARGE_MESH )
+    throw TooLargeForExport("STL");
 }
 
 //================================================================================
@@ -1614,7 +1646,9 @@ void SMESH_Mesh::ExportCGNS(const char *        file,
                             const char *        meshName,
                             const bool          groupElemsByType)
 {
+
   int res = Driver_Mesh::DRS_FAIL;
+  SMESH_TRY;
 
   // pass group names to SMESHDS
   std::map<int, SMESH_Group*>::iterator it = _mapGroup.begin();
@@ -1644,6 +1678,11 @@ void SMESH_Mesh::ExportCGNS(const char *        file,
   }
 
 #endif
+  SMESH_CATCH( SMESH::throwSalomeEx );
+
+  if ( res == Driver_Mesh::DRS_TOO_LARGE_MESH )
+    throw TooLargeForExport("CGNS");
+
   if ( res != Driver_Mesh::DRS_OK )
     throw SALOME_Exception("Export failed");
 }
@@ -1658,12 +1697,20 @@ void SMESH_Mesh::ExportGMF(const char *        file,
                            const SMESHDS_Mesh* meshDS,
                            bool                withRequiredGroups)
 {
+  Driver_Mesh::Status status;
+  SMESH_TRY;
+
   DriverGMF_Write myWriter;
   myWriter.SetFile( file );
   myWriter.SetMesh( const_cast<SMESHDS_Mesh*>( meshDS ));
   myWriter.SetExportRequiredGroups( withRequiredGroups );
 
-  myWriter.Perform();
+  status = myWriter.Perform();
+
+  SMESH_CATCH( SMESH::throwSalomeEx );
+
+  if ( status == Driver_Mesh::DRS_TOO_LARGE_MESH )
+    throw TooLargeForExport("GMF");
 }
 
 //================================================================================
index 79e349f11ee672b7c08b456e3dcf082ef8a84c4d..e93fda65ea540428e6675b573a868e622a4b2ddf 100644 (file)
@@ -245,12 +245,22 @@ class SMESH_EXPORT SMESH_Mesh
    */
   typedef TopTools_IndexedDataMapOfShapeListOfShape TAncestorMap;
   const TAncestorMap& GetAncestorMap() const { return _mapAncestors; }
+
   /*!
    * \brief Check group names for duplications.
    *  Consider maximum group name length stored in MED file
    */
   bool HasDuplicatedGroupNamesMED();
 
+  /*!
+   * \brief Exception thrown by Export*() in case if a mesh is too large for export
+   *        due to limitation of a format
+   */
+  struct TooLargeForExport : public std::runtime_error
+  {
+    TooLargeForExport(const char* format):runtime_error(format) {}
+  };
+
   void ExportMED(const char *        theFile,
                  const char*         theMeshName = NULL,
                  bool                theAutoGroups = true,
index 476167a293fe829cc8b9f8c15c17136b4950a968..588829a79ed824ecd68effa708f918ae1b34ae30 100644 (file)
@@ -992,11 +992,19 @@ namespace
           aMesh->ExportGMF( aMeshOrGroup, aFilename.toUtf8().data(), toCreateGroups );
         }
       }
-      catch (const SALOME::SALOME_Exception& S_ex){
+      catch (const SALOME::SALOME_Exception& S_ex)
+      {
         wc.suspend();
-        SUIT_MessageBox::warning(SMESHGUI::desktop(),
-                                 QObject::tr("SMESH_WRN_WARNING"),
-                                 QObject::tr("SMESH_EXPORT_FAILED") + SalomeApp_Tools::ExceptionToString(S_ex));
+        if ( S_ex.details.type == SALOME::COMM && // communicate about too large mesh
+             strncmp( "format=", S_ex.details.sourceFile.in(), 7 ) == 0 )
+
+          SUIT_MessageBox::critical(SMESHGUI::desktop(),
+                                    QObject::tr("SMESH_WRN_WARNING"),
+                                    QObject::tr(S_ex.details.text.in() ));
+        else
+          SUIT_MessageBox::warning(SMESHGUI::desktop(),
+                                   QObject::tr("SMESH_WRN_WARNING"),
+                                   QObject::tr("SMESH_EXPORT_FAILED") + SalomeApp_Tools::ExceptionToString(S_ex));
         wc.resume();
       }
     }
@@ -5131,7 +5139,7 @@ bool SMESHGUI::activateModule( SUIT_Study* study )
   lab = lab + tr("INFO_COMPUTE") + "<br/>";
   lab = lab + tr("INFO_REFINE") + ":";
   items << wrap(tr("INFO_REFINE_LOCAL_SIZE"), "li")
-       << wrap(tr("INFO_REFINE_SUBMESH"), "li");
+        << wrap(tr("INFO_REFINE_SUBMESH"), "li");
   lab = lab + wrap(items.join(""), "ul");
   items.clear();
 
@@ -5139,22 +5147,22 @@ bool SMESHGUI::activateModule( SUIT_Study* study )
 
   gb = app->infoPanel()->addGroup(tr("INFO_GRP_IMPORT_MESH"));
   items << wrap("UNV", "li")
-       << wrap("MED", "li")
-       << wrap("STL", "li")
-       << wrap("CGNS", "li")
-       << wrap("SAUV", "li")
-       << wrap("GMF", "li");
+        << wrap("MED", "li")
+        << wrap("STL", "li")
+        << wrap("CGNS", "li")
+        << wrap("SAUV", "li")
+        << wrap("GMF", "li");
   lab = tr("INFO_AVAILABLE_FORMATS") + ":" + wrap(items.join(""), "ul");
   items.clear();
-  
+
   app->infoPanel()->addLabel(lab, gb);
     
   gb = app->infoPanel()->addGroup(tr("INFO_GRP_CHECK_MESH"));
   lab = tr("INFO_DISPLAY") + "<br/>";
   items << wrap(tr("INFO_QUALITY_AREA"), "li")
-       << wrap(tr("INFO_QUALITY_VOLUME"), "li")
-       << wrap(tr("INFO_QUALITY_ASPECT_RATION"), "li")
-       << wrap("...", "li");
+        << wrap(tr("INFO_QUALITY_VOLUME"), "li")
+        << wrap(tr("INFO_QUALITY_ASPECT_RATION"), "li")
+        << wrap("...", "li");
   lab = lab + tr("INFO_QUALITY_INFO") + ":" + wrap(items.join(""), "ul");
   items.clear();
   lab = lab + tr("INFO_CLIPPING");
index eacb39a854a5ede490a2684ad82d089147d69a99..a718eac92e6bb23482aadebb027cd0343f00660f 100644 (file)
 
 //-------------------------------------------------------------------------------------
 // A macro makes description of a caught exception and calls onExceptionFun(const char*).
-// Two onExceptionFun() are defined here: SMESH::throwSalomeEx() and SMESH::doNothing().
+// Several onExceptionFun() are defined here: throwSalomeEx(), doNothing() and returnError().
 // To add your own catch close, define SMY_OWN_CATCH macro before including this file.
 
 #define SMESH_CATCH( onExceptionFun )                                   \
   }                                                                     \
+                                                                        \
+  SMY_OWN_CATCH                                                         \
+                                                                        \
   catch (Standard_Failure& ex)                                          \
   {                                                                     \
     SMESH_Comment text("OCCT Exception: ");                             \
@@ -92,9 +95,6 @@
   {                                                                     \
     SMESH_CAUGHT onExceptionFun( ex.what() );                           \
   }                                                                     \
-                                                                        \
-  SMY_OWN_CATCH                                                         \
-                                                                        \
   catch (...)                                                           \
   {                                                                     \
     SMESH_CAUGHT onExceptionFun("Unknown Exception caught");            \
index 75e3de93beac60ed1740c3a9a9c5f38e6e07e634..50a7e89101aa3d2d7a7e38a6503ac70c760411aa 100644 (file)
 
 #include <vtkUnstructuredGridWriter.h>
 
-// to pass CORBA exception through SMESH_TRY
-#define SMY_OWN_CATCH catch( SALOME::SALOME_Exception& se ) { throw se; }
+// to pass CORBA exception and TooLargeForExport exception through SMESH_TRY
+#define SMY_OWN_CATCH                                                                           \
+  catch( SALOME::SALOME_Exception& se ) { throw se; }                                           \
+  catch( ::SMESH_Mesh::TooLargeForExport& ex )                                                  \
+  { SALOME::ExceptionStruct se = {                                                              \
+      SALOME::COMM,                                                                             \
+      CORBA::string_dup(SMESH_Comment("Mesh is too large for export in format ") << ex.what()), \
+      CORBA::string_dup(SMESH_Comment("format=") <<  ex.what() ), 0 };                          \
+    throw SALOME::SALOME_Exception( se );  }
 
 #include "SMESH_TryCatch.hxx" // include after OCCT headers!
 
@@ -461,8 +468,7 @@ SMESH::DriverMED_ReadStatus SMESH_Mesh_i::ImportCGNSFile( const char*  theFileNa
 
 char* SMESH_Mesh_i::GetVersionString(CORBA::Long minor, CORBA::Short nbDigits)
 {
-  string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(minor,
-                                                          nbDigits);
+  string ver = DriverMED_W_SMESHDS_Mesh::GetVersionString(minor, nbDigits);
   return CORBA::string_dup( ver.c_str() );
 }
 
@@ -3732,11 +3738,11 @@ string SMESH_Mesh_i::prepareMeshNameAndGroups(const char*    file,
  */
 //================================================================================
 
-void SMESH_Mesh_i::ExportMED(const char*        file,
-                             CORBA::Boolean     auto_groups,
-                             CORBA::Long        version,
-                             CORBA::Boolean     overwrite,
-                             CORBA::Boolean     autoDimension)
+void SMESH_Mesh_i::ExportMED(const char*    file,
+                             CORBA::Boolean auto_groups,
+                             CORBA::Long    version,
+                             CORBA::Boolean overwrite,
+                             CORBA::Boolean autoDimension)
 {
   //MESSAGE("MED minor version: "<< minor);
   SMESH_TRY;
@@ -3763,10 +3769,9 @@ void SMESH_Mesh_i::ExportMED(const char*        file,
  */
 //================================================================================
 
-void SMESH_Mesh_i::ExportSAUV (const char* file,
-                               CORBA::Boolean auto_groups)
+void SMESH_Mesh_i::ExportSAUV( const char* file, CORBA::Boolean auto_groups )
 {
-  Unexpect aCatch(SALOME_SalomeException);
+  SMESH_TRY;
   if ( _preMeshInfo )
     _preMeshInfo->FullLoadFromFile();
 
@@ -3774,6 +3779,8 @@ void SMESH_Mesh_i::ExportSAUV (const char* file,
   TPythonDump() << SMESH::SMESH_Mesh_var( _this())
                 << ".ExportSAUV( r'" << file << "', " << auto_groups << " )";
   _impl->ExportSAUV(file, aMeshName.c_str(), auto_groups);
+
+  SMESH_CATCH( SMESH::throwCorbaException );
 }
 
 
@@ -3785,18 +3792,20 @@ void SMESH_Mesh_i::ExportSAUV (const char* file,
 
 void SMESH_Mesh_i::ExportDAT (const char *file)
 {
-  Unexpect aCatch(SALOME_SalomeException);
+  SMESH_TRY;
   if ( _preMeshInfo )
     _preMeshInfo->FullLoadFromFile();
 
-  // Update Python script
   // check names of groups
   checkGroupNames();
+  // Update Python script
   TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportDAT( r'" << file << "' )";
 
   // Perform Export
   PrepareForWriting(file);
   _impl->ExportDAT(file);
+
+  SMESH_CATCH( SMESH::throwCorbaException );
 }
 
 //================================================================================
@@ -3807,18 +3816,20 @@ void SMESH_Mesh_i::ExportDAT (const char *file)
 
 void SMESH_Mesh_i::ExportUNV (const char *file)
 {
-  Unexpect aCatch(SALOME_SalomeException);
+  SMESH_TRY;
   if ( _preMeshInfo )
     _preMeshInfo->FullLoadFromFile();
 
-  // Update Python script
   // check names of groups
   checkGroupNames();
+  // Update Python script
   TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportUNV( r'" << file << "' )";
 
   // Perform Export
   PrepareForWriting(file);
   _impl->ExportUNV(file);
+
+  SMESH_CATCH( SMESH::throwCorbaException );
 }
 
 //================================================================================
@@ -3829,13 +3840,13 @@ void SMESH_Mesh_i::ExportUNV (const char *file)
 
 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
 {
-  Unexpect aCatch(SALOME_SalomeException);
+  SMESH_TRY;
   if ( _preMeshInfo )
     _preMeshInfo->FullLoadFromFile();
 
-  // Update Python script
   // check names of groups
   checkGroupNames();
+  // Update Python script
   TPythonDump() << SMESH::SMESH_Mesh_var(_this())
                 << ".ExportSTL( r'" << file << "', " << isascii << " )";
 
@@ -3847,6 +3858,8 @@ void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
   // Perform Export
   PrepareForWriting( file );
   _impl->ExportSTL( file, isascii, name.in() );
+
+  SMESH_CATCH( SMESH::throwCorbaException );
 }
 
 //================================================================================
@@ -4249,7 +4262,7 @@ void SMESH_Mesh_i::exportMEDFields( DriverMED_W_Field&        fieldWriter,
 void SMESH_Mesh_i::ExportPartToDAT(::SMESH::SMESH_IDSource_ptr meshPart,
                                    const char*                 file)
 {
-  Unexpect aCatch(SALOME_SalomeException);
+  SMESH_TRY;
   if ( _preMeshInfo )
     _preMeshInfo->FullLoadFromFile();
 
@@ -4260,6 +4273,8 @@ void SMESH_Mesh_i::ExportPartToDAT(::SMESH::SMESH_IDSource_ptr meshPart,
 
   TPythonDump() << SMESH::SMESH_Mesh_var(_this())
                 << ".ExportPartToDAT( " << meshPart << ", r'" << file << "' )";
+
+  SMESH_CATCH( SMESH::throwCorbaException );
 }
 //================================================================================
 /*!
@@ -4270,7 +4285,7 @@ void SMESH_Mesh_i::ExportPartToDAT(::SMESH::SMESH_IDSource_ptr meshPart,
 void SMESH_Mesh_i::ExportPartToUNV(::SMESH::SMESH_IDSource_ptr meshPart,
                                    const char*                 file)
 {
-  Unexpect aCatch(SALOME_SalomeException);
+  SMESH_TRY;
   if ( _preMeshInfo )
     _preMeshInfo->FullLoadFromFile();
 
@@ -4281,6 +4296,8 @@ void SMESH_Mesh_i::ExportPartToUNV(::SMESH::SMESH_IDSource_ptr meshPart,
 
   TPythonDump() << SMESH::SMESH_Mesh_var(_this())
                 << ".ExportPartToUNV( " << meshPart<< ", r'" << file << "' )";
+
+  SMESH_CATCH( SMESH::throwCorbaException );
 }
 //================================================================================
 /*!
@@ -4292,7 +4309,7 @@ void SMESH_Mesh_i::ExportPartToSTL(::SMESH::SMESH_IDSource_ptr meshPart,
                                    const char*                 file,
                                    ::CORBA::Boolean            isascii)
 {
-  Unexpect aCatch(SALOME_SalomeException);
+  SMESH_TRY;
   if ( _preMeshInfo )
     _preMeshInfo->FullLoadFromFile();
 
@@ -4308,6 +4325,8 @@ void SMESH_Mesh_i::ExportPartToSTL(::SMESH::SMESH_IDSource_ptr meshPart,
 
   TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportPartToSTL( "
                 << meshPart<< ", r'" << file << "', " << isascii << ")";
+
+  SMESH_CATCH( SMESH::throwCorbaException );
 }
 
 //================================================================================
@@ -4322,7 +4341,7 @@ void SMESH_Mesh_i::ExportCGNS(::SMESH::SMESH_IDSource_ptr meshPart,
                               CORBA::Boolean              groupElemsByType)
 {
 #ifdef WITH_CGNS
-  Unexpect aCatch(SALOME_SalomeException);
+  SMESH_TRY;
   if ( _preMeshInfo )
     _preMeshInfo->FullLoadFromFile();
 
@@ -4344,6 +4363,9 @@ void SMESH_Mesh_i::ExportCGNS(::SMESH::SMESH_IDSource_ptr meshPart,
 
   TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportCGNS( "
                 << meshPart<< ", r'" << file << "', " << overwrite << ")";
+
+  SMESH_CATCH( SMESH::throwCorbaException );
+
 #else
   THROW_SALOME_CORBA_EXCEPTION("CGNS library is unavailable", SALOME::INTERNAL_ERROR);
 #endif
@@ -4359,7 +4381,7 @@ void SMESH_Mesh_i::ExportGMF(::SMESH::SMESH_IDSource_ptr meshPart,
                              const char*                 file,
                              bool                        withRequiredGroups)
 {
-  Unexpect aCatch(SALOME_SalomeException);
+  SMESH_TRY;
   if ( _preMeshInfo )
     _preMeshInfo->FullLoadFromFile();
 
@@ -4372,6 +4394,8 @@ void SMESH_Mesh_i::ExportGMF(::SMESH::SMESH_IDSource_ptr meshPart,
                 << meshPart<< ", r'"
                 << file << "', "
                 << withRequiredGroups << ")";
+
+  SMESH_CATCH( SMESH::throwCorbaException );
 }
 
 //=============================================================================
@@ -5526,7 +5550,7 @@ SMESH::smIdType_array* SMESH_Mesh_i::GetElementsByNodes(const SMESH::smIdType_ar
     std::vector<const SMDS_MeshElement *> elems;
     mesh->GetElementsByNodes( nn, elems, (SMDSAbs_ElementType) elemType );
     result->length( elems.size() );
-    for ( smIdType i = 0; i < elems.size(); ++i )
+    for ( size_t i = 0; i < elems.size(); ++i )
       result[i] = elems[i]->GetID();
   }
   return result._retn();