@@ -1610,7 +1610,10 @@ Casting
1610
1610
When the `convert ` argument is set to ``true `` (the default), the
1611
1611
implementation may also attempt *implicit conversions * to perform the cast.
1612
1612
1613
- The function raises a :cpp:type: `cast_error ` when the conversion fails.
1613
+ The function raises an exception when the conversion fails.
1614
+ If the type caster uses the CPython error API (e.g., ``PyErr_SetString() ``
1615
+ or ``PyErr_Format() ``) to report a failure, then :cpp:class: `python_error `
1616
+ is raised. Otherwise, :cpp:type: `cast_error ` is raised.
1614
1617
See :cpp:func: `try_cast() ` for an alternative that never raises.
1615
1618
1616
1619
.. cpp :function :: template <typename T, typename Derived> bool try_cast (const detail::api<Derived> &value, T &out, bool convert = true) noexcept
@@ -1632,7 +1635,10 @@ Casting
1632
1635
policy `policy ` is used to handle ownership-related questions when a new
1633
1636
Python object must be created.
1634
1637
1635
- The function raises a :cpp:type: `cast_error ` when the conversion fails.
1638
+ The function raises an exception when the conversion fails.
1639
+ If the type caster uses the CPython error API (e.g., ``PyErr_SetString() ``
1640
+ or ``PyErr_Format() ``) to report a failure, then :cpp:class: `python_error `
1641
+ is raised. Otherwise, :cpp:type: `cast_error ` is raised.
1636
1642
1637
1643
.. cpp :function :: template <typename T> object cast (T &&value, rv_policy policy, handle parent)
1638
1644
@@ -1641,7 +1647,10 @@ Casting
1641
1647
Python object must be created. A valid `parent ` object is required when
1642
1648
specifying a `reference_internal ` return value policy.
1643
1649
1644
- The function raises a :cpp:type: `cast_error ` when the conversion fails.
1650
+ The function raises an exception when the conversion fails.
1651
+ If the type caster uses the CPython error API (e.g., ``PyErr_SetString() ``
1652
+ or ``PyErr_Format() ``) to report a failure, then :cpp:class: `python_error `
1653
+ is raised. Otherwise, :cpp:type: `cast_error ` is raised.
1645
1654
1646
1655
.. cpp :function :: template <typename T> object find (const T &value) noexcept
1647
1656
@@ -1655,7 +1664,10 @@ Casting
1655
1664
value policy `policy ` is used to handle ownership-related questions when a
1656
1665
new Python objects must be created.
1657
1666
1658
- The function raises a :cpp:type: `cast_error ` when the conversion fails.
1667
+ The function raises an exception when the conversion fails.
1668
+ If the type caster uses the CPython error API (e.g., ``PyErr_SetString() ``
1669
+ or ``PyErr_Format() ``) to report a failure, then :cpp:class: `python_error `
1670
+ is raised. Otherwise, :cpp:type: `cast_error ` is raised.
1659
1671
1660
1672
Common binding annotations
1661
1673
--------------------------
0 commit comments