Posts Tagged ‘.net’

C# .NET Exception stack hierachy

Posted in Uncategorized on July 23rd, 2009 by ph-lee – Be the first to comment

After getting to know ruby’s exceptions I decided to revisit them in C# .NET. Ruby has a small set of exceptions which developers can use in comparison to .NET framework which has many more. Although I do like the MSDN Library, I couldn’t find a quick and easy way of seeing an overview of all the exceptions built in the framework for browsing. After being inspired by [Sieger] in his Ruby’s Exception Hierarchy article I’d thought I do the same for C# .NET, and here’s the result…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
System.Exception
   System.SystemException
      System.OutOfMemoryException
         System.InsufficientMemoryException
      System.StackOverflowException
      System.DataMisalignedException
      System.ExecutionEngineException
      System.MemberAccessException
         System.FieldAccessException
         System.MethodAccessException
         System.MissingMemberException
            System.MissingFieldException
            System.MissingMethodException
      System.AccessViolationException
      System.AppDomainUnloadedException
      System.ArgumentException
         System.ArgumentNullException
         System.ArgumentOutOfRangeException
         System.DuplicateWaitObjectException
         System.Text.DecoderFallbackException
         System.Text.EncoderFallbackException
      System.ArithmeticException
         System.DivideByZeroException
         System.NotFiniteNumberException
         System.OverflowException
      System.ArrayTypeMismatchException
      System.BadImageFormatException
      System.CannotUnloadAppDomainException
      System.TypeUnloadedException
      System.ContextMarshalException
      System.TypeLoadException
         System.EntryPointNotFoundException
         System.DllNotFoundException
      System.FormatException
         System.Reflection.CustomAttributeFormatException
      System.IndexOutOfRangeException
      System.InvalidCastException
      System.InvalidOperationException
         System.ObjectDisposedException
      System.InvalidProgramException
      System.MulticastNotSupportedException
      System.NotImplementedException
      System.NotSupportedException
         System.PlatformNotSupportedException
      System.NullReferenceException
      System.OperationCanceledException
      System.RankException
      System.TimeoutException
      System.TypeInitializationException
      System.UnauthorizedAccessException
         System.Security.AccessControl.PrivilegeNotHeldException
      System.Threading.AbandonedMutexException
      System.Threading.SynchronizationLockException
      System.Threading.ThreadAbortException
      System.Threading.ThreadInterruptedException
      System.Threading.ThreadStateException
      System.Threading.ThreadStartException
      System.Collections.Generic.KeyNotFoundException
      System.Reflection.AmbiguousMatchException
      System.Reflection.ReflectionTypeLoadException
      System.Runtime.Serialization.SerializationException
      System.Resources.MissingManifestResourceException
      System.Resources.MissingSatelliteAssemblyException
      System.Security.Policy.PolicyException
      System.Runtime.InteropServices.ExternalException
         System.Runtime.InteropServices.COMException
         System.Runtime.InteropServices.SEHException
      System.Runtime.InteropServices.InvalidOleVariantTypeException
      System.Runtime.InteropServices.MarshalDirectiveException
      System.Runtime.InteropServices.InvalidComObjectException
      System.Runtime.InteropServices.SafeArrayRankMismatchException
      System.Runtime.InteropServices.SafeArrayTypeMismatchException
      System.IO.IOException
         System.IO.DirectoryNotFoundException
         System.IO.DriveNotFoundException
         System.IO.EndOfStreamException
         System.IO.FileLoadException
         System.IO.FileNotFoundException
         System.IO.PathTooLongException
      System.Security.XmlSyntaxException
      System.Security.SecurityException
      System.Security.HostProtectionException
      System.Security.VerificationException
      System.Runtime.Remoting.RemotingException
         System.Runtime.Remoting.RemotingTimeoutException
      System.Runtime.Remoting.ServerException
      System.Security.Cryptography.CryptographicException
         System.Security.Cryptography.CryptographicUnexpectedOperationException
      System.Security.Principal.IdentityNotMappedException
   System.ApplicationException
      System.Threading.WaitHandleCannotBeOpenedException
      System.Reflection.InvalidFilterCriteriaException
      System.Reflection.TargetException
      System.Reflection.TargetInvocationException
      System.Reflection.TargetParameterCountException
   System.ASSERT
   System.Reflection.MetadataException
   System.Runtime.CompilerServices.RuntimeWrappedException
   System.IO.IsolatedStorage.IsolatedStorageException

By seeing the hierachy in full it should help developers manage their exceptions, expecially when trying to manage deep call stacks and ensuring they are handled in the correct order, helping to pin-point errors more precisely.

I’ve posted the source code used to generate the above output over at github.

Hope this has helped.