tailieunhanh - Chapter 13 - Exception Handling

Exception handling is the process of responding to the occurrence, during computation, of exceptions – anomalous or exceptional events requiring special processing – often changing the normal flow of program execution. It is provided by specialized programming language constructs or computer hardware mechanisms. | Chapter 13 - Exception Handling Outline Introduction Exception-Handling Overview Other Error-Handling Techniques Simple Exception-Handling Example: Divide by Zero Rethrowing an Exception Exception Specifications Processing Unexpected Exceptions Stack Unwinding Constructors, Destructors and Exception Handling Exceptions and Inheritance Processing new Failures Class auto_ptr and Dynamic Memory Allocation Standard Library Exception Hierarchy Introduction Exceptions Indicates problem occurred in program Not common An "exception" to a program that usually works Exception Handling Resolve exceptions Program may be able to continue Controlled termination Write fault-tolerant programs As an example, we will handle a divide-by-zero error Exception-Handling Overview Consider pseudocode Perform a task If the preceding task did not execute correctly Perform error processing Perform next task If the preceding . | Chapter 13 - Exception Handling Outline Introduction Exception-Handling Overview Other Error-Handling Techniques Simple Exception-Handling Example: Divide by Zero Rethrowing an Exception Exception Specifications Processing Unexpected Exceptions Stack Unwinding Constructors, Destructors and Exception Handling Exceptions and Inheritance Processing new Failures Class auto_ptr and Dynamic Memory Allocation Standard Library Exception Hierarchy Introduction Exceptions Indicates problem occurred in program Not common An "exception" to a program that usually works Exception Handling Resolve exceptions Program may be able to continue Controlled termination Write fault-tolerant programs As an example, we will handle a divide-by-zero error Exception-Handling Overview Consider pseudocode Perform a task If the preceding task did not execute correctly Perform error processing Perform next task If the preceding task did not execute correctly Perform error processing Mixing logic and error handling Can make program difficult to read/debug Exception handling removes error correction from "main line" of program Exception-Handling Overview Exception handling For synchronous errors (divide by zero, null pointer) Cannot handle asynchronous errors (independent of program) Disk I/O, mouse, keyboard, network messages Easy to handle errors Terminology Function that has error throws an exception Exception handler (if it exists) can deal with problem Catches and handles exception If no exception handler, uncaught exception Could terminate program Exception-Handling Overview C++ code try { code that may raise exception } catch (exceptionType){ code to handle exception } try block encloses code that may raise exception One or more catch blocks follow Catch and handle exception, if appropriate Take parameter; if named, can access exception object Exception-Handling Overview Throw

crossorigin="anonymous">
Đã 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.