Working with Specific Exceptions

The .NET Framework provides a significant number of specific exception classes, all inheriting from the base Exception class. In the .NET Framework documentation, you'll find tables listing all the possible exceptions that might occur when you call any method. For example, Table 12.2, taken from the .NET Framework documentation, makes it easy to determine what might go wrong when calling the File.Open method.

Table 12.2. Exception Types That Can Be Generated When You're Attempting to Open a File
Exception Type Condition
SecurityException The caller to this routine does not have sufficient permissions.
ArgumentException The path is empty, contains invalid characters, or contains only whitespace.
FileNotFoundException ...

Get ASP.NET Developer's JumpStart now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.