All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 "pxr/external/boost/python/handle.hpp"
11
12#include <string>
13
14PXR_NAMESPACE_OPEN_SCOPE
15
16struct TfPyExceptionState {
17 TfPyExceptionState(pxr_boost::python::handle<> const &type,
18 pxr_boost::python::handle<> const &value,
19 pxr_boost::python::handle<> const &trace) :
20 _type(type), _value(value), _trace(trace) {}
21
22 TF_API
23 ~TfPyExceptionState();
24
25 TF_API
26 TfPyExceptionState (TfPyExceptionState const &);
27
28 TF_API
29 TfPyExceptionState &operator=(TfPyExceptionState const &);
30
31 // Extract Python's current exception state as by PyErr_Fetch() and return
32 // it in a TfPyExceptionState. This leaves Python's current exception state
33 // clear.
34 TF_API
35 static TfPyExceptionState Fetch();
36
37 pxr_boost::python::handle<> const &GetType() const { return _type; }
38 pxr_boost::python::handle<> const &GetValue() const { return _value; }
39 pxr_boost::python::handle<> const &GetTrace() const { return _trace; }
40
41 // Move this object's exception state into Python's current exception state,
42 // as by PyErr_Restore(). This leaves this object's exception state clear.
43 TF_API
44 void Restore();
45
46 // Format a Python traceback for the exception state held by this object, as
47 // by traceback.format_exception().
48 TF_API
49 std::string GetExceptionString() const;
50
51private:
52 pxr_boost::python::handle<> _type, _value, _trace;
53};
54
55PXR_NAMESPACE_CLOSE_SCOPE