Skip to content

Configure SWIG to make a Python wrapper for C++ exceptions

Ammar Nejati requested to merge addPyExc into r21

The SWIG wrappers are modified to automatically produce a Python wrapper for any C++ exception thrown.

See https://www.swig.org/Doc4.1/Library.html#Library_stl_exceptions.

As an example, the result of the reported crash in issue #674 (closed) is (Python 3.11 under Windows 10)

> py .\ba_crash.py
Traceback (most recent call last):
  File "C:\tmp\ba_crash.py", line 56, in <module>
    res=simulation.simulate()
        ^^^^^^^^^^^^^^^^^^^^^
  File "C:\opt\multipython\Python311\Lib\site-packages\bornagain\lib\libBornAgainSim.py", line 2687, in simulate
    return _libBornAgainSim.ISimulation_simulate(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: BornAgain C++ Exception: Unexpected error(s) in simulation thread(s):
Rough interfaces not yet supported for polarized simulation (issue #564)
Rough interfaces not yet supported for polarized simulation (issue #564)
source or detector below horizon not yet implemented for polarized scattering
Rough interfaces not yet supported for polarized simulation (issue #564)

Resolves #674 (closed) and #685 (closed)

Edited by Ammar Nejati

Merge request reports