TAILIEUCHUNG - C++ for Mathematicians An Introduction for Students and Professionals phần 8

Chúng tôi cũng cho thấy làm thế nào để sửa đổi các định dạng đầu ra (ví dụ, làm thế nào để tăng số lượng các chữ số được in sau khi các điểm thập phân). Chúng tôi minh họa cho rất nhiều những ý tưởng này bằng cách tạo ra một lớp học để phân tích các tập tin | Odds and Ends 341 This program defines a procedure named quotient see lines 5-8 that takes two double arguments and returns their quotient. If this procedure is invoked with q equal to zero then the quotient is undefined. In this case the procedure throws an exception. Notice that there is no try catch block in the quotient procedure it is the responsibility of the procedure that invokes quotient in this example main to handle the exception. Inside main the call to quotient is embedded in a try block lines 12-21 . If quotient runs normally . its second argument is not zero then line 18 executes normally. Execution then proceeds to line 20 then the catch block lines 22-25 is skipped and the program continues at line 27. However if at line 18 the second argument sent to quotient is zero then quotient throws an exception. The value of the numerator is thrown. The rest of the try block is skipped that is line 20 is not executed. At this point the computer searches for a catch statement whose type matches the type of the thrown value. Because a double value is thrown by quotient it is caught at line 22. Now the catch block executes with top set equal to the thrown value. An error message is printed line 23 followed by a call to a system procedure named exit. This causes the program to stop executing immediately. Consequently the statements following the catch block statements that would typically execute were it not for the call to exit are not executed. If possible the catch block should repair any damage caused by the exceptional situation so the program can continue running. However some errors are sufficiently serious that continued execution does not make sense. In that case a call to exit causes the program to stop running. Note that exit can be called inside any procedure not just in main . The exit procedure takes an integer valued argument this value is passed back to the operating system. If your C program is invoked by a script the script can use that .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.