Skip to content

Commit 7ee9cf6

Browse files
author
Eric Niebler
committed
stl_iterator does better error handling
[SVN r42836]
1 parent 03a7236 commit 7ee9cf6

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/object/stl_iterator.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Distributed under the Boost Software License, Version 1.0. (See
33
// accompanying file LICENSE_1_0.txt or copy at
44
// http://www.boost.org/LICENSE_1_0.txt)
5+
//
6+
// Credits:
7+
// Andreas Kl\:ockner for fixing increment() to handle
8+
// error conditions.
59

610
#include <boost/python/object.hpp>
711
#include <boost/python/handle.hpp>
@@ -27,6 +31,8 @@ void stl_input_iterator_impl::increment()
2731
{
2832
this->ob_ = boost::python::handle<>(
2933
boost::python::allow_null(PyIter_Next(this->it_.ptr())));
34+
if (PyErr_Occurred())
35+
throw boost::python::error_already_set();
3036
}
3137

3238
bool stl_input_iterator_impl::equal(stl_input_iterator_impl const &that) const

test/stl_iterator.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
3
1313
4
1414
5
15+
>>> def generator():
16+
... yield 1
17+
... yield 2
18+
... raise RuntimeError, "oops"
19+
>>> try:
20+
... x.assign(iter(generator()))
21+
... print "NOT OK"
22+
... except RuntimeError:
23+
... print "OK"
24+
OK
1525
'''
1626
def run(args = None):
1727
import sys

0 commit comments

Comments
 (0)