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

Skip to content

Catching exceptions from iterator MoveNext() (related to #475) #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
crashing exception test
  • Loading branch information
Rickard Holmberg committed Aug 9, 2017
commit 31a4482debc5b7000de35ef9efaaace9caa06dae
9 changes: 9 additions & 0 deletions src/testing/exceptiontest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;

namespace Python.Test
{
Expand Down Expand Up @@ -54,6 +56,13 @@ public static bool ThrowException()
throw new OverflowException("error");
}

public static IEnumerable<int> ThrowExceptionInIterator()
{
yield return 1;
yield return 2;
throw new OverflowException("error");
}

public static void ThrowChainedExceptions()
{
try
Expand Down
14 changes: 14 additions & 0 deletions src/tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,17 @@ def test_chained_exceptions():
assert exc.Message == msg
assert exc.__cause__ == exc.InnerException
exc = exc.__cause__

def test_iteration_exception():
from Python.Test import ExceptionTest
from System import OverflowException

val = ExceptionTest.ThrowExceptionInIterator().__iter__()
assert next(val) == 1
assert next(val) == 2
with pytest.raises(OverflowException) as cm:
next(val)

exc = cm.value

assert isinstance(exc, OverflowException)