switched internal usage of cast_error exception to reference_cast_error

This commit is contained in:
Wenzel Jakob 2016-07-01 16:07:35 +02:00
parent 472ffbba96
commit 0006259508
3 changed files with 3 additions and 2 deletions

View File

@ -254,7 +254,7 @@ public:
template <typename T> using cast_op_type = pybind11::detail::cast_op_type<T>; template <typename T> using cast_op_type = pybind11::detail::cast_op_type<T>;
operator type*() { return (type *) value; } operator type*() { return (type *) value; }
operator type&() { if (!value) throw cast_error(); return *((type *) value); } operator type&() { if (!value) throw reference_cast_error(); return *((type *) value); }
protected: protected:
typedef void *(*Constructor)(const void *stream); typedef void *(*Constructor)(const void *stream);

View File

@ -310,6 +310,7 @@ PYBIND11_RUNTIME_EXCEPTION(stop_iteration)
PYBIND11_RUNTIME_EXCEPTION(index_error) PYBIND11_RUNTIME_EXCEPTION(index_error)
PYBIND11_RUNTIME_EXCEPTION(value_error) PYBIND11_RUNTIME_EXCEPTION(value_error)
PYBIND11_RUNTIME_EXCEPTION(cast_error) /// Thrown when pybind11::cast or handle::call fail due to a type casting error PYBIND11_RUNTIME_EXCEPTION(cast_error) /// Thrown when pybind11::cast or handle::call fail due to a type casting error
PYBIND11_RUNTIME_EXCEPTION(reference_cast_error) /// Used internally
[[noreturn]] PYBIND11_NOINLINE inline void pybind11_fail(const char *reason) { throw std::runtime_error(reason); } [[noreturn]] PYBIND11_NOINLINE inline void pybind11_fail(const char *reason) { throw std::runtime_error(reason); }
[[noreturn]] PYBIND11_NOINLINE inline void pybind11_fail(const std::string &reason) { throw std::runtime_error(reason); } [[noreturn]] PYBIND11_NOINLINE inline void pybind11_fail(const std::string &reason) { throw std::runtime_error(reason); }

View File

@ -387,7 +387,7 @@ protected:
if ((kwargs_consumed == nkwargs || it->has_kwargs) && if ((kwargs_consumed == nkwargs || it->has_kwargs) &&
(nargs_ == it->nargs || it->has_args)) (nargs_ == it->nargs || it->has_args))
result = it->impl(it, args_, kwargs, parent); result = it->impl(it, args_, kwargs, parent);
} catch (cast_error &) { } catch (reference_cast_error &) {
result = PYBIND11_TRY_NEXT_OVERLOAD; result = PYBIND11_TRY_NEXT_OVERLOAD;
} }