Bug 4327 - SortedList<>::PutImpl() swallows exception
Summary: SortedList<>::PutImpl() swallows exception
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: master
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: Martin Baulig
Depends on:
Reported: 2012-04-07 12:37 UTC by Nicholas Frechette
Modified: 2012-06-19 21:52 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Nicholas Frechette 2012-04-07 12:37:35 UTC
If Find(key) throws an exception, it is swallowed and an
InvalidOperationException is thrown, this is something that happened
to me when my key was a System.Type and I have no way of figuring out
what happened (forcing me to use a Dictionary<> instead).

Converting the exception to an InvalidOperationException is fine, but it should perhaps wrap the actual thrown exception or at least have the same message.
Comment 1 Martin Baulig 2012-06-19 21:16:32 UTC
.NET propagates the original exception:


public class MiscTests
	class Uncomparable : IComparer<double>
		public int Compare (double x, double y)
			throw new DivideByZeroException ();

	public void Bug4327 ()
		var list = new SortedList<double, int> (new Uncomparable ());
		list.Add (Math.PI, 1);
		list.Add (Math.E, 2);
Comment 2 Martin Baulig 2012-06-19 21:20:18 UTC
Oops, that was an old version of the test case.  This one is correct:

	public void Bug4327 ()
		var list = new SortedList<double, int> (new Uncomparable ());
		list.Add (Math.PI, 1);
		try {
			list.Add (Math.E, 2);
			Assert.Fail ();
		} catch (Exception ex) {
			Assert.IsInstanceOfType (typeof (InvalidOperationException), ex);
			Assert.That (ex.InnerException != null);
			Assert.IsInstanceOfType (typeof (DivideByZeroException), ex.InnerException);
Comment 3 Martin Baulig 2012-06-19 21:51:07 UTC
Fixed; commit 018521f.

I also checked SortedDictionary and SortedSet, these don't catch Exceptions on their comparer.