[. NET] Quick notes on Objective C,

Source: Internet
Author: User

[. NET] Quick notes on Objective C,
Quick notes in Objective C #-C # key points of efficient programming

/// <Summary> /// custom Exception class /// </summary> public class MyException: Exception {public MyException (): base () {} public MyException (string s): base (s) {} public MyException (string s, Exception e): base (s, e) {} protected MyException (SerializationInfo info, streamingContext cxt): base (info, cxt ){}}

 

3. When a custom exception is thrown, the original exception should be stored in the InnerException attribute so that the exception is friendly and informative:

Public void Do () {try {// DoException ();} catch (DoException e) {var msg = $ "this problem was intentionally caused by the blogger "; throw new MyException (msg, e );}}

 

4. Different types of exceptions should be thrown only when different types of recovery operations exist. When defining exception classes, all constructors supported in the base classes must be provided. In addition, do not forget to use the InnerException attribute to save low-level exception information.

 

Forty-seven, strong exception Security Guarantee

1. Dave Abrahams defines three security exceptions to ensure the program: basic assurance, strong assurance, and non-throw assurance.

2. strong exception guarantee: a balance point is provided between recovering from an exception and simplifying Exception Handling. If an operation is interrupted due to an exception, the program will remain in the original state and the operation will be completed completely, or you will not modify any State of the program. Benefits of strong exception guarantee: if an exception is caught at any time, all normal operations to be attempted will not continue. The current state of the program is the same as that of the program.

3. make a defensive copy of the data to be modified and modify the defensive copy of the data. This intermediate operation may cause exceptions, when an exception occurs, you can exchange temporary copies with the original object.

4. The Terminator, the Dispose () method, and the target method bound to the delegate object should ensure that they do not throw an exception under any circumstances.

 

Forty-eight, try to use safe code

 

Forty-nine, CLS-compatible assembly

1. the. NET runtime environment has nothing to do with the language. The created assembly must be compatible with CLS, so that other developers can use another language to call your components.

 

50. Small and highly cohesive assembly

 

This series

Quick notes in Objective C # (1)-C # language habits

Quick notes for Objective C # (2)-. NET resource hosting

Quick notes in Objective C # (III)-use C # To express design

Quick notes for Objective C # (4)-use the framework

Quick notes in Objective C #-Dynamic Programming in C #

Quick notes for Objective C # (6)-C # key points of efficient programming

 

 

[Blogger] Anti-Bot

Http://www.cnblogs.com/liqingwen/p/6827546.html.

[Reference] Objective C #

 

Related Article

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.