Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a list of .Net Exception types and advice on when to use them?

Tags:

.net

exception

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.

like image 655
Calanus Avatar asked Jul 13 '11 08:07

Calanus


People also ask

How do you handle exceptions in C#?

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.


1 Answers

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

like image 51
Adam Houldsworth Avatar answered Sep 20 '22 11:09

Adam Houldsworth