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.
Use a try block around the statements that might throw exceptions. Once an exception occurs in the try block, the flow of control jumps to the first associated exception handler that is present anywhere in the call stack. In C#, the catch keyword is used to define an exception handler.
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:
http://msdn.microsoft.com/en-us/library/ms182338.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With