Absolute C++ (4th Edition) part 76

Absolute C++ (4th Edition) part 76. KEY BENEFIT: C++ programming concepts and techniques are presented in a straightforward style using understandable language and code. KEY TOPICS: C++ Basics; Flow of Control; Function Basics; Parameters and Overloading; Arrays; Structures and Classes; Constructors; Operator Overloading, Friends, and References; Strings; Pointers and Dynamic Arrays; Separate Compilation and Namespaces; Streams and File I/O; Recursion; Inheritance; Polymorphism and Virtual Functions; Templates; Linked Data Structures; Exception Handling; Standard Template Library; Patterns and UML. MARKET: Useful for both beginning and intermediate C++ programmers. . | Exception Handling CHAPTER SUMMARY 783 ANSWERS TO SELF-TEST EXERCISES 784 PROGRAMMING PROJECTS 785 EXCEPTION HANDLING BASICS 759 A Toy Example of Exception Handling 759 Defining Your Own Exception Classes 768 Multiple Throws and Catches 768 Pitfall Catch the More Specific Exception First 772 Tip Exception Classes Can Be Trivial 773 Throwing an Exception in a Function 773 Exception Specification 775 Pitfall Exception Specification in Derived Classes 777 PROGRAMMING TECHNIQUES FOR EXCEPTION HANDLING 779 When to Throw an Exception 779 Pitfall Uncaught Exceptions 781 Pitfall Nested try-catch Blocks 781 Pitfall Overuse of Exceptions 782 Exception Class Hierarchies 782 Testing for Available Memory 782 Rethrowing an Exception 783 Exception Handling It s the exception that proves the rule. Common maxim Introduction One way to write a program is to first assume that nothing unusual or incorrect will happen. For example if the program takes an entry off a list you might assume that the list is not empty. Once you have the program working for the core situation where things always go as planned you can then add code to take care of the exceptional cases. C has a way to reflect this approach in your code. Basically you write your code as if nothing very unusual happens. After that you use the C exception handling facilities to add code for those unusual cases. Exception handling is commonly used to handle error situations but perhaps a better way to view exceptions is as a way to handle exceptional situations. After all if your code correctly handles an error then it no longer is an error. Perhaps the most important use of exceptions is to deal with functions that have some special case that is handled differently depending on how the function is used. Perhaps the function will be used in many programs some of which will handle the special case in one way while others will handle it in some other way. For example if there is a division by zero in the function then it

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã 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.