Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6b03c63

Browse files
rickardraysearchabessen
authored and
abessen
committed
Catch exceptions from iterator.MoveNext()
(cherry picked from commit 8531755)
1 parent d0f34e9 commit 6b03c63

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/runtime/iterator.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,21 @@ public Iterator(IEnumerator e)
2323
public static IntPtr tp_iternext(IntPtr ob)
2424
{
2525
var self = GetManagedObject(ob) as Iterator;
26-
if (!self.iter.MoveNext())
26+
try
2727
{
28-
Exceptions.SetError(Exceptions.StopIteration, Runtime.PyNone);
28+
if (!self.iter.MoveNext())
29+
{
30+
Exceptions.SetError(Exceptions.StopIteration, Runtime.PyNone);
31+
return IntPtr.Zero;
32+
}
33+
}
34+
catch (Exception e)
35+
{
36+
if (e.InnerException != null)
37+
{
38+
e = e.InnerException;
39+
}
40+
Exceptions.SetError(e);
2941
return IntPtr.Zero;
3042
}
3143
object item = self.iter.Current;

0 commit comments

Comments
 (0)