How To Handle An InvalidOperationException In A foreach Loop Containing yield return?
<p>I have the following code in which I am trying to take each element returned by an ICollectionView and translate it into a different object.</p>

<pre><code>    public IEnumerator GetEnumerator()
    {
        foreach (TOriginal original in _collectionView)
        {
            if (!Equals(original, null))
            {
                yield return GetTranslated(original);
            }
            else
            {
                yield return default(TTranslated);
            }
        }
    }
</code></pre>

<p>If _collectionView is changed during the foreach (this is happening in my test app) then it throws an InvalidOperationException, but I can't wrap the foreach loop in a try/catch because VisualStudio complains "'yield return' statement couldn't appear in a try/catch block".</p>

<p>How can I handle the exception?</p>
