From 9fc1cca75056e65dd46aadfec1ddbe3e1577b1c3 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 11 Nov 2021 12:31:08 +0300 Subject: [PATCH] Avoid aborting if module is not registered yet --- src/KernelHelpers/KernelServices.i | 29 +++++++++++++++++++++ src/KernelHelpers/SALOME_KernelServices.cxx | 12 ++++++--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/KernelHelpers/KernelServices.i b/src/KernelHelpers/KernelServices.i index 2d00ccd2a..7dbfd4af4 100644 --- a/src/KernelHelpers/KernelServices.i +++ b/src/KernelHelpers/KernelServices.i @@ -23,8 +23,37 @@ %{ #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); diff --git a/src/KernelHelpers/SALOME_KernelServices.cxx b/src/KernelHelpers/SALOME_KernelServices.cxx index efc9bf85e..30d81f6b1 100644 --- a/src/KernelHelpers/SALOME_KernelServices.cxx +++ b/src/KernelHelpers/SALOME_KernelServices.cxx @@ -21,6 +21,7 @@ #include "SALOME_KernelServices.hxx" #include "SALOME_Fake_NamingService.hxx" +#include "Utils_SALOME_Exception.hxx" #include #include @@ -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(); } } -- 2.39.2