April 2014
Intermediate to advanced
960 pages
22h 9m
English
When your program throws an exception, you can use a try-catch-finally block to catch the exception and examine it to determine its class. When you want to throw your own exception, however, you must know what exception classes are available so that you can pick the best one to throw. The following sections describe some of the most useful classes for throwing exceptions.
The following table lists some of the most useful exception classes in C#. If possible you should use one of these standard classes when you need to throw an exception.
| Class | Purpose |
AmbiguousMatchException | The program could not figure out which overloaded object method to use. |
ArgumentException | An argument is invalid. |
ArgumentNullException | An argument that cannot be null has the value null. |
ArgumentOutOfRangeException | An argument is out of its allowed range. |
ArithmeticException | An arithmetic, casting, or conversion operation has occurred. |
ArrayTypeMismatchException | The program tried to store the wrong type of item in an array. |
ConfigurationException | A configuration setting is invalid. |
ConstraintException | A data operation violates a database constraint. |
DataException | The ancestor class for ADO.NET exception classes. |
DirectoryNotFoundException | A needed directory is missing. |
DivideByZeroException | The program tried to divide by zero. |
DuplicateNameException | An ADO.NET operation encountered a duplicate name. For example, it tried to create two tables ... |
Read now
Unlock full access