1. 02 Apr, 2017 1 commit
    • Roman Miroshnychenko's avatar
      Add a method to check Python exception types (#772) · 83a8a977
      Roman Miroshnychenko authored
      This commit adds `error_already_set::matches()` convenience method to
      check if the exception trapped by `error_already_set` matches a given
      Python exception type. This will address #700 by providing a less
      verbose way to check exceptions.
      83a8a977
  2. 20 Nov, 2016 1 commit
  3. 16 Sep, 2016 1 commit
    • Jason Rhinelander's avatar
      Added py::register_exception for simple case (#296) · b3794f10
      Jason Rhinelander authored
      The custom exception handling added in PR #273 is robust, but is overly
      complex for declaring the most common simple C++ -> Python exception
      mapping that needs only to copy `what()`.  This add a simpler
      `py::register_exception<CppExp>(module, "PyExp");` function that greatly
      simplifies the common basic case of translation of a simple CppException
      into a simple PythonException, while not removing the more advanced
      capabilities of defining custom exception handlers.
      b3794f10
  4. 10 Sep, 2016 1 commit
    • Dean Moldovan's avatar
      Make error_already_set fetch and hold the Python error · 135ba8de
      Dean Moldovan authored
      This clears the Python error at the error_already_set throw site, thus
      allowing Python calls to be made in destructors which are triggered by
      the exception. This is preferable to the alternative, which would be
      guarding every Python API call with an error_scope.
      
      This effectively flips the behavior of error_already_set. Previously,
      it was assumed that the error stays in Python, so handling the exception
      in C++ would require explicitly calling PyErr_Clear(), but nothing was
      needed to propagate the error to Python. With this change, handling the
      error in C++ does not require a PyErr_Clear() call, but propagating the
      error to Python requires an explicit error_already_set::restore().
      
      The change does not break old code which explicitly calls PyErr_Clear()
      for cleanup, which should be the majority of user code. The need for an
      explicit restore() call does break old code, but this should be mostly
      confined to the library and not user code.
      135ba8de
  5. 07 Sep, 2016 1 commit
  6. 19 Aug, 2016 1 commit
    • Dean Moldovan's avatar
      Port tests to pytest · a0c1ccf0
      Dean Moldovan authored
      Use simple asserts and pytest's powerful introspection to make testing
      simpler. This merges the old .py/.ref file pairs into simple .py files
      where the expected values are right next to the code being tested.
      
      This commit does not touch the C++ part of the code and replicates the
      Python tests exactly like the old .ref-file-based approach.
      a0c1ccf0