Skip to content

Commit

Permalink
Catch exceptions from iterator.MoveNext()
Browse files Browse the repository at this point in the history
(cherry picked from commit 8531755)
  • Loading branch information
rickardraysearch authored and abessen committed Jun 25, 2018
1 parent d0f34e9 commit 6b03c63
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/runtime/iterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,21 @@ public Iterator(IEnumerator e)
public static IntPtr tp_iternext(IntPtr ob)
{
var self = GetManagedObject(ob) as Iterator;
if (!self.iter.MoveNext())
try
{
Exceptions.SetError(Exceptions.StopIteration, Runtime.PyNone);
if (!self.iter.MoveNext())
{
Exceptions.SetError(Exceptions.StopIteration, Runtime.PyNone);
return IntPtr.Zero;
}
}
catch (Exception e)
{
if (e.InnerException != null)
{
e = e.InnerException;
}
Exceptions.SetError(e);
return IntPtr.Zero;
}
object item = self.iter.Current;
Expand Down

0 comments on commit 6b03c63

Please sign in to comment.