C # Errors and exceptions

Source: Internet
Author: User

<1> has two very important exception classes that derive from the System.Exception class

System.SystemException: The class is usually thrown by the. NET runtime, or has a very general nature and can be thrown by almost all applications, and the subclass of the system.systemexception exception includes exceptions that represent fatal and non-fatal errors;

System.ApplicationException: This class is very important because it is a third-party defined exception base class, and if any exceptions that you define override the application's unique error conditions, you should make them derive directly or indirectly from the System.ApplicationException class;

<2>try...catch...finally to perform the steps:

1. The executed procedure flows into the try block;

2. If no exception occurs in the try block, the operation will be performed normally in the block. When the program flow reaches the end of the try block, if there is a finally block, the program flow automatically enters the finally block, but if an error is detected in the try block, the program flow jumps to the catch

3. Handling errors in the catch block;

4. After the catch block executes, if there is a finally block, the program flow automatically enters the finally block;

5. Execute the finally block;

Note: You can omit the finally block; you can provide any number of catch blocks to handle different types of errors, but should not contain too many catch blocks to reduce application performance

<3> Note

1. After an exception occurs, code in the try block after the exception code does not execute

Code in 2.finally blocks, whether or not an exception occurs, executes before a return in a try or catch

Cannot write return statement in 3.finally block

A return statement is in the 4.try block, and finally is executed and executed before the return;

5. Even if there is no code in the catch,finally will execute, but finally the code will not be executed;

C # Errors and exceptions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.