Does anyone know of a list of .Net Exception types .e.g. ArgumentNullException
and under what circumstances you should use them? At the moment I'm just guessing based on the type name but I would rather get it right.
-
1I don't know of a list perse, but I know that MSDN will tell you what most exceptions are for. Isn't that good enough? – Tony The Lion Jul 13 '11 at 8:23
-
1Take a look at this MSDN topic: SystemException Class – platon Jul 13 '11 at 8:25
-
Yes MSDN will give you a list but to browse through msdn each time looking at each page for each exception to work out which one to choose will take ages. What we need is a summary of most common exceptions and friendly advice on when you would use each of them – Calanus Jul 13 '11 at 8:26
-
1Arrghh that's no good - throwing SystemException each time is exactly what we shouldn't be doing – Calanus Jul 13 '11 at 8:27
-
this topic contains the list of exceptions :). That is why I posted a link to it here :) – platon Jul 13 '11 at 8:27
A list of them:
http://mikevallotton.wordpress.com/2009/07/08/net-exceptions-all-of-them/
As for the circumstance, it depends, most of the time they make sense based on their name and arguments. ArgumentNullException
, for example, is usually used when checking method / constructor arguments for null values.
Then you have others such as FileNotFoundException
, NullReferenceException
, InvalidOperationException
, as you can see they read very easily and should be used with common sense.
Update 1: as someone has suggested, they are also on MSDN:
http://msdn.microsoft.com/en-us/library/system.exception.aspx#inheritanceContinued
Here are views on common exceptions available:
https://blogs.msmvps.com/jgaylord/2009/07/08/common-and-all-system-exceptions-in-net/
http://www.developerfusion.com/article/1889/exception-handling-in-c/3/
Update 2: as for usage, Microsoft has guidelines for reserved exception types:
-
6This is also an interesting read: msdn.microsoft.com/en-us/library/ms229007.aspx – pauloya Jul 13 '11 at 8:41
-
@Paulo indeed, that one has gone on my instapaper for later :-) – Adam Houldsworth Jul 13 '11 at 8:41
-
Nice list of lists! The first list is formatted painfully, but good information, especially @Paulo's msdn link. – Abacus Jan 31 '14 at 16:06