C ++ day14 Study Notes

Source: Internet
Author: User

1. file classification
(1) text file: each byte is a valid printable ASCII code, Getline (),>
(2) binary files: bytes are continuous. You cannot use VI or more to view the file content. Read data is read by the number of bytes. Write

100 is an integer of 100, accounting for 4 bytes.
"100" is a character array, which occupies 3 bytes.

2. Exceptions
(1) Human Error: DueProgramMiscode
Objective errors: unavoidable errors

(2) Determine program Errors Based on return values. If () else () is required for callers and the meaning of return values must be clear.
Therefore, C ++ provides an exception handling mechanism.

3. Working Principle of exceptions:
1) written by programmersCodeAn exception is automatically generated when an exception occurs, and an exception object is thrown.
2) The object is passed to the place responsible for exception handling.
Throw 1; // throw an exception for the caller to handle
3) The code responsible for exception handling is responsible for unified exception handling. Try {} catch (){}
4) The exception object contains detailed information about the accident.

4. Format of the Exception Code:
Throw: Throw Exception name;
Processing: ppt368

 
Try{}Catch(Exception 1Int) {Process Code ;}Catch(Exception 2Const Char*) {Process Code ;}

When the program is normal, the Catch Block does not do anything. When an exception occurs, the program jumps from where the exception is generated to the Catch Block.
After the exception is handled, the exception is not returned.
Using try {} catch () {} to handle exceptions is a mandatory method. An exception occurs and the process ends.
If the exception type in catch () is inconsistent with the thrown exception type, no exception is caught.

5. Each catch can only handle one type of exception. The Catch Block is executed in sequence.

6 catch (...){
Process Code;
}
Exceptions of any type can be captured, but it cannot determine the type of exceptions. Generally, it is placed in the last catch block.
However, this capture is not targeted.

7. propagation characteristics of exceptions:
Hierarchical propagation: exceptions are thrown layer by layer.
After an exception occurs, the program immediately jumps to the last layer to capture the exception statement. If there is no capture statement or no matching Catch Block, the program will jump out of the current function and return to the called place.
If you skip to the main function and still do not handle exceptions, the program will terminate the process.

8. encapsulation exception (1) Use a string to describe the exception
(2) Specify the error no.
(3) disp ();
when the caught exception has an inheritance relationship, you must first capture the subclass exception, catch the parent class exception again
9. inline class
write one class to the inside of another class
exceptions are usually made into inline Class A: exp, define your own namespace by prefix
inline class, private modifier can only be used in the original, external is hidden, only public modifier can be used outside
10. Exception summary
(1) A method for checking errors
(2) you can use simple data types or custom data types
(3) generate throw E; Exception object
process try {} catch (exception type) {} --- the exception type should be the same as that thrown by throw
(4) Propagation

11. Bank Project --- object-oriented
when analyzing requirements, draw a diagram
biz object to complete business logic
value object operation data (account)
menu collects user information, user-selected business
biz collects information for a specific business
da provides file access service
account stores data

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.