none
List of C# exceptions

    Question

  • i was wondering if anyone has a master list (all) of exceptions (or a link) for C#?
    *** Please allow me to mark threads as answered and I will, Thank you ***
    Tuesday, August 11, 2009 6:28 PM

Answers

All replies

  • Because exception classes can be custom defined for each specific purpose, there's no way that there can be a complete master list of exceptions in C#. 

    For a list of a bunch of them, open Visual Studio, and press Ctrl+Alt+E, and expand "Common Language Runtime Exceptions".  That'll give you a list of the ones currently referenced by your project.


    Coding Light - Illuminated Ideas and Algorithms in Software
    Coding Light WikiTwitterLinkedInForumsBrowser
    • Marked as answer by ski_freak Tuesday, August 11, 2009 7:19 PM
    Tuesday, August 11, 2009 6:33 PM
  • Since each class in .Net can throw its own exception one can easily reference back to the MSDN help pages to get at the information. I don't really see a need for a wall chart of exceptions since one can capture any exception by the base class Exception or simply catch but ignore by using catch  { }.



    William Wegerson (www.OmegaCoder.Com)
    Tuesday, August 11, 2009 6:53 PM
  • OmegaMan,

    Too bad you can't see why such a list would be helpful. Imagine for a minute that you were writing a real application and you had the need to throw an exception. The list of exceptions (even within the currently imported namespaces) is all over the place in the intellisence and the documentation. Too bad .Net's naming convention puts the word 'Exception' at the end of all the available exceptions. If it was at the beginning they would sort together and this would be a lot easier.

    GAWD! We really hate it when you MVP's that say things like 'why would you want to do that?': It's because we write real applications that are intended for real people to use in the real world.

    I don't mean to be obnoxious, but we really do hate that.

    Tom
    Friday, September 25, 2009 2:22 AM
  • If you want to throw from your own code then a lot of the time you really should create your own exception class.

    A lot of the .Net framework exceptions aren't really designed to be thrown from user code (some specifically state they shouldn't be in the documentation, and FxCop/Code Analysis will complain about some like System.NullReferenceException). The .Net framework exceptions that can/should be thrown by user code should generally only be thrown in specific circumstances... at which point a simple list of available exceptions doesn't help because you need to know which one you should use in your circumstance, not some massive list of every possible exception. Sometimes it's obvious, i.e ArgumentException or ArgumentNullException are both fairly self-explantory as to what they mean and when you should use them... and you shouldn't re-use them for some other purpose. 

    InvalidProgramException for example, is not particularly well self-documenting by name (although the intellisense comments are good), but should not appear on a list a of exceptions you might want to throw from your code... unless perhaps you're writing a compiler.

    Throwing an InvalidOperationException is questionable, but almost certainly bad if the same method can throw the same exception type for different reasons... at which point you are probably back to creating your own exception type as the right thing to do. In fact most of the time if a method can throw the same exception for different reasons then you have a problem... your exception class is to generic so the caller won't necessarily understand why they should catch that exception, and if they do catch it they then have to figure out why it was thrown which can be awkward, especially if the exception type doesn't contain an error code or something that uniquely identifies the reason.

    What you're really asking for is not a list of all exceptions, but a list of exceptions you might want to throw, and even then I don't think that a list of exception names on it's own is really enough to do a proper job.

    Friday, September 25, 2009 2:47 AM
  • GAWD! We really hate it when you MVP's that say things like 'why would you want to do that?': It's because we write real applications that are intended for real people to use in the real world.
    Tom, 

    I just want to point out briefly that "us MVP's" also write real applications that are intended for real people to use in the real world.  The vast majority of my time is spent programming applications for use by clients in their day to day operations.  In fact, the vast majority of MVPs aren't stuck in the "ivory tower" so to speak . We're honest-to-God programmers who simply like to help people learn.  

    That being said, you can create a makeshift list of all the exceptions that are currently within scope of your application, but again, as Yort pointed out, exceptions can be created with very little effort, so there's no possible way to get a list of "all the exceptions".  Every time I add a reference, I might be adding fifteen new exceptions to my application.  

    Also, if I'm not mistaken (which I very well may be), simply typing "throw new " should make Intellisense pop up with the possibilities.  It'll list namespaces and exception classes only.  

    Coding Light - Illuminated Ideas and Algorithms in Software
    Coding Light WikiLinkedInForumsBrowser
    Friday, September 25, 2009 10:38 AM
  • OmegaMan,

    Too bad you can't see why such a list would be helpful. Imagine for a minute that you were writing a real application and you had the need to throw an exception. The list of exceptions (even within the currently imported namespaces) is all over the place in the intellisence and the documentation. Too bad .Net's naming convention puts the word 'Exception' at the end of all the available exceptions. If it was at the beginning they would sort together and this would be a lot easier.

    GAWD! We really hate it when you MVP's that say things like 'why would you want to do that?': It's because we write real applications that are intended for real people to use in the real world.

    I don't mean to be obnoxious, but we really do hate that.

    Tom
    Hi Tom,

    My response was in unison to David's reponse. Similar to two Sports commentators, one who does play by play and the other who is the color comentator who is able to provide background and insight into events. I like being the color commentator.

    David's play by play was spot on and that was the answer. There is no one list. My opinion, maybe I didn't provide a warning IMHO and to that end my bad was based on what I have seen in the industry for twenty years and that is how I handle exceptions. I hit the primary ones and leave a catch all for the rest. If time shows the code needs to handle specific ones, I will write the code to answer to that. But to try and catch every one is (IMHO) overkill.

    Now your suggestion about having intellisense give a list of the exceptions is actually a good one.

    Instead of venting towards yours truly, put in a Microsoft connect suggestion for Visual Studio for just such an operation. Because Microsoft via the forums and connect actually listens to the users for your opinions are valued just as much as mine are and should be expressed.


    William Wegerson (www.OmegaCoder.Com)
    Monday, September 28, 2009 10:19 PM
  • IntelliSense lists exceptions from the references that defined for the project.

    Open the Object Browser Window, and change the 'browsing scope' to the Framework, and type "Exception" in the search box.  Hit enter. 
    You can sort the display by object type.  You can separate methods and other members from classes.


    Mark the best replies as answers. "Fooling computers since 1971."
    Monday, September 28, 2009 10:56 PM
  • Sure there can and should be a complete master list published somewhere.

    Obviously, there has to be a list (a big list) of derived Exception classes defined within .NET itself.

    And obviously, each project can and should define their own custom Exception classes when feasible.

    And I wasn't worried about catching one, I was throwing one.

    By the way, the reason I stumbled on this thread was that I was looking to see if an existing .NET Exception class would work for me, since adding a new one is much more painful in my circumstance (CM stuff, don't ask).

    Tuesday, October 27, 2009 9:28 PM
  • Sure there can and should be a complete master list published somewhere.

    Obviously, there has to be a list (a big list) of derived Exception classes defined within .NET itself.

    And obviously, each project can and should define their own custom Exception classes when feasible.

    And I wasn't worried about catching one, I was throwing one.

    By the way, the reason I stumbled on this thread was that I was looking to see if an existing .NET Exception class would work for me, since adding a new one is much more painful in my circumstance (CM stuff, don't ask).



    Nope, it does not exist in the MSDN library.

    Sounds like a great idea for a web site though.
    Reminds me of connectionstrings.com or pinvoke.net.
    Document the stuff that isn't covered in the MSDN library...well at least not in one location.
     
    Nice ring to it ... exceptions.net ...  I'm serious, too.

    Mark the best replies as answers. "Fooling computers since 1971."
    Wednesday, October 28, 2009 12:15 AM
  • Nice ring to it ... exceptions.net ...  I'm serious, too.

    Too bad it's owned by a speculator.
    Ron Whittle - If the post is helpful or answers your question, please mark it as such. Not As Brightly Lit
    • Proposed as answer by bockfu Tuesday, July 06, 2010 9:41 PM
    Wednesday, October 28, 2009 12:45 AM
  • I found a list sometime back online.  While there is a risk the list may be obsolete, it is helpful to some programmers.  Here are a few links that may be helpful for thos looking for a list:

    http://msdn.microsoft.com/en-us/library/system.systemexception.aspx

    http://weblogs.asp.net/jgaylord/archive/2009/07/08/common-and-all-system-exceptions-in-net.aspx?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+JasonNGaylord+(Jason+N.+Gaylords+Blog)

     

    • Proposed as answer by bockfu Tuesday, July 06, 2010 9:43 PM
    • Unproposed as answer by Rudedog2MVP, Moderator Wednesday, July 07, 2010 1:02 PM
    Tuesday, July 06, 2010 9:43 PM
  • I found a list sometime back online.  While there is a risk the list may be obsolete, it is helpful to some programmers.  Here are a few links that may be helpful for thos looking for a list:

    http://msdn.microsoft.com/en-us/library/system.systemexception.aspx

    http://weblogs.asp.net/jgaylord/archive/2009/07/08/common-and-all-system-exceptions-in-net.aspx?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+JasonNGaylord+(Jason+N.+Gaylords+Blog )

     


    That first link is a list that is far from complete.  That listing only describes types in the System namespace.  There are many more exceptions not defined within the System namespace, which is the reason for the this thread.

    RuntimeWrappedException Class (System.Runtime.CompilerServices)

    OracleException Class (System.Data.OracleClient)

    WebException Class (System.Net)

    TargetInvocationException Class (System.Reflection)

    Those are just a few examples.  Thanks for the links, too.

    Rudy  =8^D


    Mark the best replies as answers. "Fooling computers since 1971."
    Wednesday, July 07, 2010 1:07 PM
  • Common Exception Types (27 Mar 2005)http://blogs.msdn.com/b/brada/archive/2005/03/27/402801.aspx
    (pasted from above link)

    +--System.Object  

       |

       |

       +--System.Exception  

           |

           |

           +--System.SystemException  

               |

               |

               +--System.ArgumentException  

               |   |

               |   |

               |   +--System.ArgumentNullException  

               |   |

               |   |

               |   +--System.ArgumentOutOfRangeException  

               |   |

               |   |

               |   +--System.DuplicateWaitObjectException  

               |

               |

               +--System.ArithmeticException  

               |   |

               |   |

               |   +--System.DivideByZeroException  

               |   |

               |   |

               |   +--System.OverflowException  

               |   |

               |   |

               |   +--System.NotFiniteNumberException

               |

               |

               +--System.ArrayTypeMismatchException  

               |

               |

               +--System.ExecutionEngineException  

               |

               |

               +--System.FormatException  

               |

               |

               +--System.IndexOutOfRangeException  

               |

               |

               +--System.InvalidCastException  

               |

               |

               +--System.InvalidOperationException  

               |   |

               |   |

               |   +--System.ObjectDisposedException  

               |

               |

               +--System.InvalidProgramException  

               |

               |

               +--System.IO.IOException  

               |   |

               |   |

               |   +--System.IO.DirectoryNotFoundException  

               |   |

               |   |

               |   +--System.IO.EndOfStreamException  

               |   |

               |   |

               |   +--System.IO.FileLoadException  

               |   |

               |   |

               |   +--System.IO.FileNotFoundException  

               |   |

               |   |

               |   +--System.IO.PathTooLongException  

               |

               |

               +--System.NotImplementedException  

               |

               |

               +--System.NotSupportedException  

               |

               |

               +--System.NullReferenceException  

               |

               |

               +--System.OutOfMemoryException  

               |

               |

               +--System.RankException  

               |

               |

               +--System.Security.SecurityException  

               |

               |

               +--System.Security.VerificationException  

               |

               |

               +--System.StackOverflowException  

               |

               |

               +--System.Threading.SynchronizationLockException  

               |

               |

               +--System.Threading.ThreadAbortException  

               |

               |

               +--System.Threading.ThreadStateException  

               |

               |

               +--System.TypeInitializationException  

               |

               |

               +--System.UnauthorizedAccessException


    • Edited by rswank Monday, February 06, 2012 5:05 PM made link hot
    Monday, February 06, 2012 5:04 PM
  • I know this thread is a bit old, but I came across it while searching for a list of exceptions; and I had to comment because I so much feel the OPs pain.

    First of all, I'm pretty sure the OP was looking for a list of standard .net exceptions, but perhaps should have specified.  Clearly no one can provide a list that includes whatever custom exceptions a given solution might have.  Perhaps something like resharper, et. al.  But what I was looking for was a list of those included in the framework and their typical use.  And the thread did get there, so yay!

    But more importantly, I really want to support the comment that it is wildly fantastically annoying when you ask a question and the response is something along the lines of "why would you want to do that?" or that can't possibly be a good idea.  Something like that.

    Its certainly not limited to this forum.  You see this sort of response on stackoverflow and wherever such forums exist.  Its just not helpful and implies that the person posing the question is asking how best to blend their cat.

    In this example, lets say that someone is wanting to find the appropriate exception to place in a Contract.Requires<T>, or elsewhere.  Is it really that useful to create your own exception that provides precisely the same functionality as an existing .Net exception?  O.o

    My question, and I do have one, is this...  Is there a compelling reason to create your own MyArgumentOutOfRangeException rather than to use the .Net ArgumentOutOfRangeException (as just one specific example)?  This thread seems to imply to me that there is, but if so what?

    If there is a perfectly good .Net exception in existence, why not use it?  And I'm not suggesting or implying a scenario where each possible exception in caught and handled.  I certainly support the idea of only catching that which is specifically useful and using a general catch (or bubbling up) all else.

    But I think it is sometimes useful to notice a condition and explicitly throw a NullReferenceException (just as an example).  And so even though other posters have succeeded in providing useful links (thank you!), I am curious if anyone can tell me why providing a list was a bad idea in the first place, and why using existing .Net exceptions is a bad idea.

    Thanks in advance!

    Friday, August 17, 2012 5:27 PM
  • Is there a compelling reason to create your own MyArgumentOutOfRangeException rather than to use the .Net ArgumentOutOfRangeException (as just one specific example)?

    Who is the eventual audience for the exception? If it is a developer and the new exception provides some type of added value then yes. But if it is a 'parroting' of the exception generated by .Net then no.

    -------------

    I will add that that no one took the suggestion to add it to connect (AFAIK) for Microsoft to consider. I don't say that to dissuade one away from the idea; just to note that it wasn't important enough for someone to champion outside a simple forum post.


    William Wegerson (www.OmegaCoder.Com)

    Wednesday, August 29, 2012 8:27 PM
  • I know this thread is a bit old, but I came across it while searching for a list of exceptions; and I had to comment because I so much feel the OPs pain.

    First of all, I'm pretty sure the OP was looking for a list of standard .net exceptions, but perhaps should have specified.  Clearly no one can provide a list that includes whatever custom exceptions a given solution might have.  Perhaps something like resharper, et. al.  But what I was looking for was a list of those included in the framework and their typical use.  And the thread did get there, so yay!

    .........


    Thanks in advance!

    Did you see my earlier post?

    "Open the Object Browser Window, and change the 'browsing scope' to the Framework, and type "Exception" in the search box.  Hit enter.  You can sort the display by object type.  You can separate methods and other members from classes."

    The Object Browser Window can provide a brief summary of the Exception type.  You can always look the type in the MSDN library for additional information.  I think the Object Browser is the single most useful tool in the entire IDE.  I use it far, far more than any other tool.


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

    Thursday, August 30, 2012 12:33 PM
  • Did you see my earlier post?

    I say this in only the nicest of ways and out of *full respect for you* but....maybe change your signature to "Fooling computers and obfuscating (obvious) forum answers since 71".

    ;-)


    William Wegerson (www.OmegaCoder.Com)

    Thursday, August 30, 2012 12:43 PM
  • Insyst_Tom has a point. Just because you write applications and just because you think there's no point because we can create custom exceptions, a list is useful because you may end up creating custom exceptions, not knowing there was an appropriate exception already in the common collection. How about for Powershell script writers who want to provide more information than just throwing a System.Exception every time, but don't want to have to write their own custom exceptions library? There are many reasons that you and I both may not know of and it is small minded to answer a question with "Why would you want to".

    I would like to add that the most experienced developer has never encountered every scenario that requires software development, to ask why someone makes a request is arrogant and ignorant of their situation.

    1 further point; if there's no point having a list of exceptions when we can create custom ones, why does Microsoft provide a poster of the core .Net framework with every version, when they and we create many more libraries that extend it, or in many cases, are used instead of various parts of the core library?

    Microsoft lacks intuition and it seems their MVP's have a similar flaw, which in many ways, makes a lot of sense.

    For those who don't think, not knowing and stupidity are the same thing (i.e not MVP's), here's a good list: -

    http://mikevallotton.wordpress.com/2009/07/08/net-exceptions-all-of-them/



    • Edited by Some Name_ Friday, October 05, 2012 8:47 PM
    Friday, October 05, 2012 8:34 PM
  • If that were true, many of those Exceptions wouldn't be public!
    Friday, October 05, 2012 8:41 PM
  • If that were true, many of those Exceptions wouldn't be public!

    Of course they must be public. An exception which isn't public cannot be caught specifically.
    • Edited by Louis.fr Monday, October 08, 2012 11:27 AM
    Monday, October 08, 2012 11:27 AM
  • you can see the list of common exceptions on here:

    http://www.authorcode.com/list-of-common-c-exceptions/

    And you can see the full list of the exception in the System namespace on the MSDN:

    MSDN list of exceptions

    thanks


    Tuesday, April 02, 2013 5:22 AM
  • I'm rather late to the party but the MSDN page on the Exception Class, http://msdn.microsoft.com/en-us/library/system.exception.aspx , has a list of the .NET exceptions that derive from the base Exception class.

    Look at the section titled Inheritance Hierarchy and click on the more... button.  I'm guessing it lists about 50 - 70 exceptions.

    Unfortunately this isn't a complete list.  It appears to be only the top-level exceptions that derive directly from the Exception class.  However, if you follow a link in the Inheritance Hierarchy it'll take you to a derived exception, and that exception in turn will have its own inheritance hierarchy.

    If you had a lot of time you could work your way through the links on all these pages and build up a complete picture of the exception hierarchy in the .NET framework.  Perhaps someone could write a script to scrape the pages and build up a list.

    Here is a Microsoft blog post that has a very basic hierarchy of .NET exceptions:  http://blogs.msdn.com/b/brada/archive/2005/03/27/402801.aspx

    Very incomplete but may be useful.

    Sunday, April 27, 2014 9:44 AM
  • i was wondering if anyone has a master list (all) of exceptions (or a link) for C#?
    *** Please allow me to mark threads as answered and I will, Thank you ***

    check this one...c# exceptions in detail......c# exceptions

    leven

    Saturday, May 03, 2014 5:23 AM