Basic syntax for exception handling in C #

Source: Internet
Author: User

1         Static voidMain (string[] args)2         {3             intx =0;4             Try5             {6                 inty = -/x;7             }8             Catch(Exception e)9             {Ten Console.WriteLine (e.message); One                 //throw;//throw out an exception A             } -             finally -             { theConsole.WriteLine ("Anyway,we arrive here"); -             } - Console.readkey (); +}

Exception classes for 2.c#

1 varAE =NewArgumentException ();//parameter Exception class2 varAne =NewArgumentNullException ();//parameter is an empty exception3 varAore =NewArgumentOutOfRangeException ();//parameter exceeds range exception4 varDne =NewDirectoryNotFoundException ();//IO exception path not found5 varFne =NewFileNotFoundException ();//File not found6 varIoE =NewInvalidOperationException ();//operator Exception7 varNIE =NewNotImplementedException ();//method Call Exception

3.c# Handling Exceptions

If the logical execution of the IF statement is much faster than the exception execution, then in the actual development process generally at the bottom of the use of Try catch, at the top of the business to prevent error causes the business to crash, also use try catch.

Basic syntax for 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.