Export (0) Print
Expand All

Handling and Throwing Exceptions

Programs must be able to uniformly handle errors that occur during execution. The common language runtime greatly assists the design of fault-tolerant software by providing a model for notifying programs of errors in a uniform way. All .NET Framework operations indicate failure by throwing exceptions.

Traditionally, a language's error handling model relied on either the language's unique way of detecting errors and locating handlers for them, or on the error handling mechanism provided by the operating system. The runtime implements exception handling with the following features:

  • Handles exceptions without regard for the language that generates the exception or the language that handles the exception.

  • Does not require any particular language syntax for handling exceptions, but allows each language to define its own syntax.

  • Allows exceptions to be thrown across process and even machine boundaries.

Exceptions offer several advantages over other methods of error notification, such as return codes. Failures do not go unnoticed. Invalid values do not continue to propagate through the system. You do not have to check return codes. Exception-handling code can be easily added to increase program reliability.

Exception Class and Properties

Describes the elements of an exception object.

Exception Hierarchy

Describes the exceptions that most exceptions derive from.

Exception Handling

Explains how to handle exceptions using catch, throw, and finally statements.

Best Practices for Handling Exceptions

Describes suggested methods for handling exceptions.

Exception Class

Reference information for the class that all exceptions inherit from.

SystemException Class

Reference information for the class that all system-generated exceptions derive from.

Community Additions

ADD
Show:
© 2014 Microsoft