boost::python Export Custom Exception

后端 未结 4 1208
天涯浪人
天涯浪人 2020-12-13 03:24

I am currently writing a C++ extension for Python using Boost.Python. A function in this extension may generate an exception containing information about the error (beyond

4条回答
  •  旧巷少年郎
    2020-12-13 03:36

    The answer given by Jack Edmonds defines a Python "exception" class that does not inherit Exception (or any other built-in Python exception class). So although it can be caught with

    except my_cpp_extension.MyCPPException as e:
        ...
    

    it can not be caught with the usual catch all

    except Exception as e:
        ...
    

    Here is how to create a custom Python exception class that does inherit Exception.

提交回复
热议问题