[Mono-bugs] [Bug 75828][Cos] New - Erroneous "Unhandled Exception" Output

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Tue Aug 16 17:33:29 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 jd.conley at coversant.net.

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

--- shadow/75828	2005-08-16 17:33:29.000000000 -0400
+++ shadow/75828.tmp.31631	2005-08-16 17:33:29.000000000 -0400
@@ -0,0 +1,103 @@
+Bug#: 75828
+Product: Mono: Runtime
+Version: unspecified
+OS: All
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: Unknown
+Priority: Cosmetic
+Component: misc
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: jd.conley at coversant.net               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Erroneous "Unhandled Exception" Output
+
+Description of Problem:
+When an exception happens in an asynchronous BeginInvoke delegate call the
+runtime properly bubbles that exception up to the consumer when EndInvoke
+is called.  However, the runtime outputs that there was an Unhandled
+Exception, when in fact it was handled.
+
+Steps to reproduce the problem:
+1. Call a delegate with a BeginInvoke.
+2. Throw an exception in the new thread.
+3. Call EndInvoke.
+
+Actual Results:
+Console output of "Unhandled Excecption:" + ex.ToString()
+
+Expected Results:
+The console should be silent, as the exception is handled.
+
+How often does this happen? 
+Every Time
+
+Test Cases (that pass, but see "Unhandled Exception" output to the console):
+namespace AsyncDelegates
+{
+	[TestFixture()]
+	public class AsyncInvocationTests
+	{
+		private delegate void DoSomethingDelegate();
+
+		private Exception _asyncException;
+		private System.Threading.ManualResetEvent _waitEvent;
+
+		[Test(), ExpectedException(typeof(InvalidOperationException))]
+		public void AsyncDelegateException()
+		{
+			DoSomethingDelegate d = new DoSomethingDelegate(TestAsync);
+			IAsyncResult result = d.BeginInvoke(null, null);
+
+			if (!result.AsyncWaitHandle.WaitOne(5000, false))
+				Assertion.Fail("Should have got the callback even though there was an
+exception");
+
+			d.EndInvoke(result);
+		}
+
+		[Test(), ExpectedException(typeof(InvalidOperationException))]
+		public void AsyncDelegateAsyncException()
+		{
+			_asyncException = null;
+			_waitEvent = new System.Threading.ManualResetEvent(false);
+
+
+			DoSomethingDelegate d = new DoSomethingDelegate(TestAsync);
+			d.BeginInvoke(new AsyncCallback(AsynCallback), d);
+			
+			if (!_waitEvent.WaitOne(5000, false))
+				Assertion.Fail("Should have got the callback even though there was an
+exception");
+
+			Assertion.Assert("No async exception received.", null != _asyncException);
+
+			throw _asyncException;
+		}
+
+		private void AsynCallback(IAsyncResult ar)
+		{
+			try
+			{
+				((DoSomethingDelegate)ar.AsyncState).EndInvoke(ar);
+			}
+			catch (Exception ex)
+			{
+				_asyncException = ex;
+			}
+			finally
+			{
+				_waitEvent.Set();
+			}
+		}
+
+		private void TestAsync()
+		{
+			throw new InvalidOperationException("Not allowed!");
+		}
+	}
+}


More information about the mono-bugs mailing list