Go to the documentation of this file.
24 const char *
what() const noexcept
override {
return message.c_str(); }
38 const char *
what() const noexcept
override {
return message.c_str(); }
48 virtual const char *
what() const noexcept {
return message.c_str(); }
65 const char *
what() const noexcept
override {
return message.c_str(); }
86 const char *
what() const noexcept
override {
return message.c_str(); }
105 py::object o =
foo[
"bar"];
106 }
catch (py::error_already_set &ex) {
107 ex.discard_as_unraisable(
s);
115 m.def(
"throw_std_exception",
116 []() {
throw std::runtime_error(
"This exception was intentionally thrown."); });
120 ex_storage.call_once_and_store_result(
121 [&]() {
return py::exception<MyException>(
m,
"MyException"); });
125 std::rethrow_exception(
p);
135 static const auto *
const exd =
new py::exception<MyExceptionUseDeprecatedOperatorCall>(
136 m,
"MyExceptionUseDeprecatedOperatorCall");
140 std::rethrow_exception(
p);
143 #if defined(__INTEL_COMPILER) || defined(__NVCOMPILER)
148 PYBIND11_WARNING_PUSH
164 std::rethrow_exception(
p);
178 std::rethrow_exception(
p);
186 auto ex5 = py::register_exception<MyException5>(
m,
"MyException5");
188 py::register_exception<MyException5_1>(
m,
"MyException5_1", ex5.ptr());
195 std::rethrow_exception(
p);
203 []() {
throw MyException(
"this error should go to py::exception<MyException>"); });
204 m.def(
"throws1d", []() {
206 "this error should go to py::exception<MyExceptionUseDeprecatedOperatorCall>");
209 []() {
throw MyException2(
"this error should go to a standard Python exception"); });
210 m.def(
"throws3", []() {
throw MyException3(
"this error cannot be translated"); });
211 m.def(
"throws4", []() {
throw MyException4(
"this error is rethrown"); });
213 []() {
throw MyException5(
"this is a helper-defined translated exception"); });
214 m.def(
"throws5_1", []() {
throw MyException5_1(
"MyException5 subclass"); });
215 m.def(
"throws6", []() {
throw MyException6(
"MyException6 only handled in this module"); });
216 m.def(
"throws_logic_error", []() {
217 throw std::logic_error(
"this error should fall through to the standard handler");
219 m.def(
"throws_overflow_error", []() {
throw std::overflow_error(
""); });
220 m.def(
"throws_local_error", []() {
throw LocalException(
"never caught"); });
222 m.def(
"exception_matches", []() {
226 py::object o =
foo[
"bar"];
227 }
catch (py::error_already_set &ex) {
228 if (!ex.matches(PyExc_KeyError)) {
235 m.def(
"exception_matches_base", []() {
239 py::object o =
foo[
"bar"];
240 }
catch (py::error_already_set &ex) {
241 if (!ex.matches(PyExc_Exception)) {
248 m.def(
"modulenotfound_exception_matches_base", []() {
251 py::module_::import(
"nonexistent");
252 }
catch (py::error_already_set &ex) {
253 if (!ex.matches(PyExc_ImportError)) {
261 m.def(
"throw_already_set", [](
bool err) {
266 throw py::error_already_set();
267 }
catch (
const std::runtime_error &
e) {
268 if ((err &&
e.what() != std::string(
"ValueError: foo"))
271 != std::string(
"Internal error: pybind11::error_already_set called "
272 "while Python error indicator not set."))) {
274 throw std::runtime_error(
"error message mismatch");
281 throw py::error_already_set();
284 m.def(
"python_call_in_destructor", [](
const py::dict &
d) {
289 throw py::error_already_set();
290 }
catch (
const py::error_already_set &) {
296 m.def(
"python_alreadyset_in_destructor", [](
const py::str &
s) {
303 [
m](
const py::object &exc_type,
const py::function &
f,
const py::args &
args) {
306 }
catch (py::error_already_set &ex) {
307 if (ex.matches(exc_type)) {
318 m.def(
"simple_bool_passthrough", [](
bool x) {
return x; });
320 m.def(
"throw_should_be_translated_to_key_error", []() {
throw shared_exception(); });
322 m.def(
"raise_from", []() {
325 throw py::error_already_set();
328 m.def(
"raise_from_already_set", []() {
331 throw py::error_already_set();
332 }
catch (py::error_already_set &
e) {
334 throw py::error_already_set();
338 m.def(
"throw_nested_exception", []() {
340 throw std::runtime_error(
"Inner Exception");
341 }
catch (
const std::runtime_error &) {
342 std::throw_with_nested(std::runtime_error(
"Outer Exception"));
346 m.def(
"error_already_set_what", [](
const py::object &exc_type,
const py::object &exc_value) {
348 std::string what = py::error_already_set().what();
349 bool py_err_set_after_what = (PyErr_Occurred() !=
nullptr);
354 m.def(
"test_cross_module_interleaved_error_already_set", []() {
355 auto cm = py::module_::import(
"cross_module_interleaved_error_already_set");
356 auto interleaved_error_already_set
357 =
reinterpret_cast<void (*)()
>(PyLong_AsVoidPtr(
cm.attr(
"funcaddr").ptr()));
358 interleaved_error_already_set();
361 m.def(
"test_error_already_set_double_restore", [](
bool dry_run) {
363 py::error_already_set
e;
372 m.def(
"test_pypy_oserror_normalization", []() {
374 py::module_::import(
"io").attr(
"open")(
"this_filename_must_not_exist",
"r");
375 }
catch (
const py::error_already_set &
e) {
381 m.def(
"test_fn_cast_int", [](
const py::function &
fn) {
387 m.def(
"return_exception_void", []() {
return py::exception<void>(); });
virtual const char * what() const noexcept
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
#define PYBIND11_CONSTINIT
#define PYBIND11_WARNING_DISABLE_GCC(name)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static const double d[K][N]
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
PYBIND11_WARNING_PUSH PYBIND11_WARNING_POP
void register_exception_translator(ExceptionTranslator &&translator)
MyException(const char *m)
MyException2(const char *m)
void raise_from(PyObject *type, const char *message)
const char * what() const noexcept override
void foo(CV_QUALIFIER Matrix3d &m)
MyException3(const char *m)
const char * what() const noexcept override
void register_local_exception_translator(ExceptionTranslator &&translator)
void set_error(const handle &type, const char *message)
MyException3 & operator=(const MyException3 &)=default
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
~PythonAlreadySetInDestructor()
virtual ~MyException3()=default
PYBIND11_WARNING_PUSH PYBIND11_WARNING_DISABLE_MSVC(5054) PYBIND11_WARNING_POP static_assert(EIGEN_VERSION_AT_LEAST(3
TEST_SUBMODULE(exceptions, m)
~PythonCallInDestructor()
const char * what() const noexcept override
MyException5(const std::string &what)
MyException6(const char *m)
MyException4(const char *m)
PythonAlreadySetInDestructor(const py::str &s)
const char * what() const noexcept override
#define PYBIND11_WARNING_DISABLE_CLANG(name)
PythonCallInDestructor(const py::dict &d)
gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:39:27