Compartir a través de


Handling and Throwing Exceptions

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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.

In This Section

Reference

  • 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.