Salome HOME
Avoid aborting if module is not registered yet
authorvsr <vsr@opencascade.com>
Thu, 11 Nov 2021 09:31:08 +0000 (12:31 +0300)
committervsr <vsr@opencascade.com>
Thu, 11 Nov 2021 09:31:08 +0000 (12:31 +0300)
src/KernelHelpers/KernelServices.i
src/KernelHelpers/SALOME_KernelServices.cxx

index 2d00ccd2aa84d019cc036af2422d14e73b58625d..7dbfd4af4eac4033be23a097586f6c47cac45fec 100644 (file)
 
 %{
 #include "KernelServices.hxx"
+#include "Utils_SALOME_Exception.hxx"
 %}
 
+%exceptionclass SALOME_Exception;
+
+class SALOME_Exception
+{
+public:
+  SALOME_Exception(const std::string& text);
+  ~SALOME_Exception() noexcept;
+  const char *what() const noexcept;
+  %extend
+  {
+    std::string __str__() const
+    {
+      return std::string(self->what());
+    }
+  }
+};
+
+%exception {
+  try {
+    $action
+  }
+  catch (SALOME_Exception& _e) {
+    // Reraise with SWIG_Python_Raise
+    SWIG_Python_Raise(SWIG_NewPointerObj((new SALOME_Exception(static_cast< const SALOME_Exception& >(_e))),SWIGTYPE_p_SALOME_Exception,SWIG_POINTER_OWN), "SALOME_Exception", SWIGTYPE_p_SALOME_Exception);
+    SWIG_fail;
+  }
+}
+
 %inline
 {
     void RegisterCompoInternal(const std::string& compoName, const std::string& compoIOR);
index efc9bf85e2a708816763c10c3dd0be1a3e7780b9..30d81f6b13e5f7e79a520cdb187bd8063d8990b1 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "SALOME_KernelServices.hxx"
 #include "SALOME_Fake_NamingService.hxx"
+#include "Utils_SALOME_Exception.hxx"
 
 #include <map>
 #include <memory>
@@ -176,16 +177,19 @@ namespace KERNEL {
   
   CORBA::Object_var RetrieveCompo(const std::string& compoName)
   {
+    CORBA::Object_var ret;
     auto it = _compo_map.find(compoName);
     if( it != _compo_map.end() )
     {
-      return (*it).second;
+      ret = (*it).second;
     }
     else
     {
-      SALOME::SALOME_Exception ex(createSalomeException("RetrieveCompo : not implemented yet !"));
-      throw ex;
-    //GetLCC()->FindOrLoad_Component( "FactoryServer", compoName );
+      //SALOME::SALOME_Exception ex(createSalomeException("RetrieveCompo : not implemented yet !"));
+      //throw ex;
+      throw SALOME_Exception("RetrieveCompo : not implemented yet !");
+      //GetLCC()->FindOrLoad_Component( "FactoryServer", compoName );
     }
+    return ret._retn();
   }
 }