Loading...
Searching...
No Matches
pyExceptionState.h
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7
8#include "pxr/pxr.h"
9#include "pxr/base/tf/api.h"
10#include <boost/python/handle.hpp>
11
12PXR_NAMESPACE_OPEN_SCOPE
13
14struct TfPyExceptionState {
15 TfPyExceptionState(boost::python::handle<> const &type,
16 boost::python::handle<> const &value,
17 boost::python::handle<> const &trace) :
18 _type(type), _value(value), _trace(trace) {}
19
20 TF_API
21 ~TfPyExceptionState();
22
23 TF_API
24 TfPyExceptionState (TfPyExceptionState const &);
25
26 TF_API
27 TfPyExceptionState &operator=(TfPyExceptionState const &);
28
29 // Extract Python's current exception state as by PyErr_Fetch() and return
30 // it in a TfPyExceptionState. This leaves Python's current exception state
31 // clear.
32 TF_API
33 static TfPyExceptionState Fetch();
34
35 boost::python::handle<> const &GetType() const { return _type; }
36 boost::python::handle<> const &GetValue() const { return _value; }
37 boost::python::handle<> const &GetTrace() const { return _trace; }
38
39 // Move this object's exception state into Python's current exception state,
40 // as by PyErr_Restore(). This leaves this object's exception state clear.
41 TF_API
42 void Restore();
43
44 // Format a Python traceback for the exception state held by this object, as
45 // by traceback.format_exception().
46 TF_API
47 std::string GetExceptionString() const;
48
49private:
50 boost::python::handle<> _type, _value, _trace;
51};
52
53PXR_NAMESPACE_CLOSE_SCOPE