cppyabm  1.0.17
An agent-based library to integrate C++ and Python
Public Member Functions | List of all members
error_already_set Class Reference

#include <pytypes.h>

Inheritance diagram for error_already_set:

Public Member Functions

 error_already_set ()
 
 error_already_set (const error_already_set &)=default
 
 error_already_set (error_already_set &&)=default
 
 ~error_already_set () override
 
void restore ()
 
void discard_as_unraisable (object err_context)
 
void discard_as_unraisable (const char *err_context)
 
void clear ()
 
bool matches (handle exc) const
 
const objecttype () const
 
const objectvalue () const
 
const objecttrace () const
 

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 326 of file pytypes.h.

Constructor & Destructor Documentation

◆ error_already_set() [1/3]

error_already_set::error_already_set ( )
inline

Constructs a new exception from the current Python error indicator, if any. The current Python error indicator will be cleared.

Definition at line 330 of file pytypes.h.

◆ error_already_set() [2/3]

error_already_set::error_already_set ( const error_already_set )
default

◆ error_already_set() [3/3]

error_already_set::error_already_set ( error_already_set &&  )
default

◆ ~error_already_set()

error_already_set::~error_already_set ( )
inlineoverride

Definition at line 2261 of file pybind11.h.

Member Function Documentation

◆ clear()

void error_already_set::clear ( )
inline

Definition at line 360 of file pytypes.h.

◆ discard_as_unraisable() [1/2]

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

Definition at line 354 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 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. For example, func could be helpful. After this call, the current object no longer stores the error variables, and neither does Python.

Definition at line 350 of file pytypes.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 365 of file pytypes.h.

◆ restore()

void error_already_set::restore ( )
inline

Give the currently-held error back to Python, if any. If there is currently a Python error already set it is cleared first. After this call, the current object no longer stores the error variables (but the .what() string is still available).

Definition at line 342 of file pytypes.h.

◆ trace()

const object& error_already_set::trace ( ) const
inline

Definition at line 369 of file pytypes.h.

◆ type()

const object& error_already_set::type ( ) const
inline

Definition at line 367 of file pytypes.h.

◆ value()

const object& error_already_set::value ( ) const
inline

Definition at line 368 of file pytypes.h.


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