FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python/src/errors.cpp at develop · boostorg/python · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
boostorg
/
python
Public
Notifications
You must be signed in to change notification settings
Fork
223
Star
537
Code
Issues
173
Pull requests
34
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python
/
src
/
errors.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
123 lines (107 loc) · 2.79 KB
Breadcrumbs
python
/
src
/
errors.cpp
Copy path
File metadata and controls
123 lines (107 loc) · 2.79 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
Copyright David Abrahams 2001.
//
Distributed under the Boost Software License, Version 1.0. (See
//
accompanying file LICENSE_1_0.txt or copy at
//
http://www.boost.org/LICENSE_1_0.txt)
#
ifndef
BOOST_PYTHON_SOURCE
#
define
BOOST_PYTHON_SOURCE
#
endif
#
include
<
boost/python/errors.hpp
>
#
include
<
boost/cast.hpp
>
#
include
<
boost/python/detail/exception_handler.hpp
>
#
include
<
boost/python/detail/pymutex.hpp
>
namespace
boost
{
namespace
python
{
#
ifdef
Py_GIL_DISABLED
namespace
detail
{
//
Global mutex for protecting all Boost.Python internal state
pymutex&
get_global_mutex
()
{
static
pymutex mutex;
return
mutex;
}
}
#
endif
error_already_set::~error_already_set
() {}
//
IMPORTANT: this function may only be called from within a catch block!
BOOST_PYTHON_DECL
bool
handle_exception_impl
(function0<
void
> f)
{
try
{
detail::exception_handler* handler_chain =
nullptr
;
{
BOOST_PYTHON_LOCK_STATE
();
handler_chain = detail::exception_handler::chain;
}
if
(handler_chain)
return
handler_chain->
handle
(f);
f
();
return
false
;
}
catch
(
const
boost::python::error_already_set&)
{
//
The python error reporting has already been handled.
}
catch
(
const
std::bad_alloc&)
{
PyErr_NoMemory
();
}
catch
(
const
bad_numeric_cast& x)
{
PyErr_SetString
(PyExc_OverflowError, x.
what
());
}
catch
(
const
std::out_of_range& x)
{
PyErr_SetString
(PyExc_IndexError, x.
what
());
}
catch
(
const
std::invalid_argument& x)
{
PyErr_SetString
(PyExc_ValueError, x.
what
());
}
catch
(
const
std::exception& x)
{
PyErr_SetString
(PyExc_RuntimeError, x.
what
());
}
catch
(...)
{
PyErr_SetString
(PyExc_RuntimeError,
"
unidentifiable C++ exception
"
);
}
return
true
;
}
void
BOOST_PYTHON_DECL
throw_error_already_set
()
{
throw
error_already_set
();
}
namespace
detail
{
bool
exception_handler::operator
()(function0<
void
>
const
& f)
const
{
if
(m_next)
{
return
m_next->
handle
(f);
}
else
{
f
();
return
false
;
}
}
exception_handler::exception_handler
(handler_function
const
& impl)
: m_impl(impl)
, m_next(
0
)
{
BOOST_PYTHON_LOCK_STATE
();
if
(chain !=
0
)
tail->
m_next
=
this
;
else
chain =
this
;
tail =
this
;
}
exception_handler* exception_handler::chain;
exception_handler* exception_handler::tail;
BOOST_PYTHON_DECL
void
register_exception_handler
(handler_function
const
& f)
{
//
the constructor links the new object into a handler chain, so
//
this object isn't actaully leaked (until, of course, the
//
interpreter exits).
new
exception_handler
(f);
}
}
//
namespace boost::python::detail
}}
//
namespace boost::python
Back
|
FazBrowse Home
|
New Git URL