Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
error_already_set Class Reference

#include <pytypes.h>

Inheritance diagram for error_already_set:
Inheritance graph
[legend]

Public Member Functions

void clear ()
 
void discard_as_unraisable (const char *err_context)
 
void discard_as_unraisable (object err_context)
 
 error_already_set ()
 
bool matches (handle exc) const
 
void restore ()
 
const objecttrace () const
 
const objecttype () const
 
const objectvalue () const
 
const char * what () const noexcept override
 

Static Private Member Functions

static void m_fetched_error_deleter (detail::error_fetch_and_normalize *raw_ptr)
 

Private Attributes

std::shared_ptr< detail::error_fetch_and_normalize > m_fetched_error
 

Detailed Description

Fetch and hold an error which was already set in Python. An instance of this is typically thrown to propagate python-side errors back through C++ which can either be caught manually or else falls back to the function dispatcher (which then raises the captured error back to python).

Definition at line 739 of file pytypes.h.

Constructor & Destructor Documentation

◆ error_already_set()

error_already_set::error_already_set ( )
inline

Fetches the current Python exception (using PyErr_Fetch()), which will clear the current Python error indicator.

Definition at line 743 of file pytypes.h.

Member Function Documentation

◆ clear()

void error_already_set::clear ( )
inline

Definition at line 776 of file pytypes.h.

◆ discard_as_unraisable() [1/2]

void error_already_set::discard_as_unraisable ( const char *  err_context)
inline

An alternate version of discard_as_unraisable(), where a string provides information on the location of the error. For example, __func__ could be helpful. WARNING: The GIL must be held when this member function is called!

Definition at line 770 of file pytypes.h.

◆ discard_as_unraisable() [2/2]

void error_already_set::discard_as_unraisable ( object  err_context)
inline

If it is impossible to raise the currently-held error, such as in a destructor, we can write it out using Python's unraisable hook (sys.unraisablehook). The error context should be some object whose repr() helps identify the location of the error. Python already knows the type and value of the error, so there is no need to repeat that.

Definition at line 763 of file pytypes.h.

◆ m_fetched_error_deleter()

void error_already_set::m_fetched_error_deleter ( detail::error_fetch_and_normalize *  raw_ptr)
inlinestaticprivate

WARNING: This custom deleter needs to acquire the Python GIL. This can lead to crashes (undefined behavior) if the Python interpreter is finalizing.

Definition at line 2776 of file pybind11.h.

◆ matches()

bool error_already_set::matches ( handle  exc) const
inline

Check if the currently trapped error type matches the given Python exception class (or a subclass thereof). May also be passed a tuple to search for any exception class matches in the given tuple.

Definition at line 781 of file pytypes.h.

◆ restore()

void error_already_set::restore ( )
inline

Restores the currently-held Python error (which will clear the Python error indicator first if already set). NOTE: This member function will always restore the normalized exception, which may or may not be the original Python exception. WARNING: The GIL must be held when this member function is called!

Definition at line 757 of file pytypes.h.

◆ trace()

const object& error_already_set::trace ( ) const
inline

Definition at line 785 of file pytypes.h.

◆ type()

const object& error_already_set::type ( ) const
inline

Definition at line 783 of file pytypes.h.

◆ value()

const object& error_already_set::value ( ) const
inline

Definition at line 784 of file pytypes.h.

◆ what()

const char * error_already_set::what ( ) const
inlineoverridenoexcept

The what() result is built lazily on demand. WARNING: This member function needs to acquire the Python GIL. This can lead to crashes (undefined behavior) if the Python interpreter is finalizing.

Definition at line 2782 of file pybind11.h.

Member Data Documentation

◆ m_fetched_error

std::shared_ptr<detail::error_fetch_and_normalize> error_already_set::m_fetched_error
private

Definition at line 788 of file pytypes.h.


The documentation for this class was generated from the following files:


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:43:35