System.Exception—catch an NotSupportedException
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| C# Code Snippets |
| See also |
| edit |
This C# code snippet first causes and then catches an NotSupportedException.
using System; using System.Collections; class ArrayAddition { public static void Main() { string[] strings = {"1", "2"}; try { AddToList (strings, "3"); } catch (NotSupportedException e) { Console.WriteLine ("Exception: {0}", e); } } public static void AddToList(IList il, object o) { il.Add(o); } }
| NotSupportedException example (program output) |
| Exception: System.NotSupportedException: Collection was of a fixed size. at System.Array.System.Collections.IList.Add(Object value) at ArrayAddition.AddToList(IList il, Object o) in Program.cs:line 17 at ArrayAddition.Main() in Program.cs:line 9 |