Exception Handling in C #

Source: Internet
Author: User

today we are studying the exception handling mechanism in C #.

First, exception handling is used to prevent errors that can be predicted but not completely prevented. Using the proper exception handling mechanism can effectively prevent the program from crashing. In this sense, some of the other bugs in the program, such as bugs, errors need to use the application to handle user errors.

Exception handling has the following fields: Try,throw,catch. Use exception handling to use the System.Exception namespace. The thrown exception will continue along the inheritance chain of the class until it is passed to System.Exception (this is the same mechanism as C + + and Java).

1  Public classTest2 {3     Public Static voidMain ()4    {5Console.WriteLine ("Enter Main ...");6Test T =NewTest ();7 t.func1 ();8Console.WriteLine ("Exit Main ...");9    }Ten     Public voidFunc1 () One    { AConsole.WriteLine ("Enter Func1 ..."); - Func2 (); -Console.WriteLine ("Exit Func1 ..."); the     } -  -  Public voidFunc2 () - { +Console.WriteLine ("Enter Func2 ..."); -   Throw Newsystem.applicationexception (); +Console.WriteLine ("Exit Func2 ..."); A   } at  } -}

Exception Handling in C #

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.