← Back to all articles

Pop Quiz: Asynchronous Methods & Contract Errors

This is for people wanting to expand their asynchronous brains!

Pop Quiz

Here is a question for you; What will this seemly trivial program segment do?

void X()
{
    try
    {
        Y();
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}

async void Y()
{
    throw new NotImplementedException();
}

Before you answer, consider another question; Is there a behavioral difference between these two methods?

IEnumerable J()
{
    throw new NotImplementedException();
}

IEnumerable K()
{
    throw new NotImplementedException();
    yield return -1;
}

Don’t worry some Rx posts are coming soon!

Comments