[Mono-bugs] [Bug 76100][Nor] Changed - mcs: yield in a lock block generates exception

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Fri Sep 16 03:04:46 EDT 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by schwimmlehrer at hotmail.com.

http://bugzilla.ximian.com/show_bug.cgi?id=76100

--- shadow/76100	2005-09-14 06:35:00.000000000 -0400
+++ shadow/76100.tmp.19315	2005-09-16 03:04:46.000000000 -0400
@@ -62,6 +62,47 @@
 Should compile and run (lock the object as long as the loop is executed).
 MCS should not expose its stack trace especially on code that seems to be
 valid (at least to me and to Microsoft csc).
 
 How often does this happen? 
 Always
+
+------- Additional Comments From schwimmlehrer at hotmail.com  2005-09-16 03:04 -------
+According to the Microsoft documentation it is ok to have yield in a
+try block if there is no catch clause:
+http://winfx.msdn.microsoft.com/library/en-us/dv_csref/html/1089194f-9e53-46a2-8642-53ccbe9d414d.asp
+
+I did a quick test. This is valid with csc. It is similar to having
+lock () 
+{}
+
+  try
+  {
+   for (int i = 0; i < 10; i++)
+    yield return true;
+  }
+  finally
+  {
+  }
+
+
+  lock (lockit)
+  {
+   for (int i = 0; i < 10; i++)
+    yield return true;
+  }
+
+This is invalid:
+
+  try
+  {
+   for (int i = 0; i < 10; i++)
+    yield return true;
+  }
+  catch (Exception e)
+  {
+  }
+
+
+Test.cs(38,5): error CS1626: Cannot yield a value in the body of a try
+block with a catch clause
+


More information about the mono-bugs mailing list