tailieunhanh - Lecture Object oriented programming - Lecture no 29

This chapter presents the following content: Primitive data types, integer types, floating-point types, char type, ASCII table, unicode standard, type conversions – promotions, type casting, prefix/postfix modes for increment/decrement operators, embedded assignment expressions, conditional operator expressions, expression evaluation practice, short-circuit evaluation, empty statement, break statement within a loop. | CSC241: Object Oriented Programming Lecture No 29 Previous Lecture Exception in Distance class Re-throwing an exception Exception with arguments bad_alloc class set_new_handler function Today’s Lecture Handler function Standard library Exception Hierarchy Example program Queue class using array A linked list data storage class Handler function This function will be called if new fails This provides a method to handling all new failure with a uniform approach set_new_handler function is used to register a handler function If new fails to allocate memory, then If handler function is registered then it will be called If handler function is not registered then Cont. If new allocates memory successfully, it returns a pointer to that memory If new fails to allocate memory, then If set_new_handler did not register a new-handler function, new throws a bad_alloc exception If a new-handler function has been registered, the new-handler function is called Task performed by handler-function Make . | CSC241: Object Oriented Programming Lecture No 29 Previous Lecture Exception in Distance class Re-throwing an exception Exception with arguments bad_alloc class set_new_handler function Today’s Lecture Handler function Standard library Exception Hierarchy Example program Queue class using array A linked list data storage class Handler function This function will be called if new fails This provides a method to handling all new failure with a uniform approach set_new_handler function is used to register a handler function If new fails to allocate memory, then If handler function is registered then it will be called If handler function is not registered then Cont. If new allocates memory successfully, it returns a pointer to that memory If new fails to allocate memory, then If set_new_handler did not register a new-handler function, new throws a bad_alloc exception If a new-handler function has been registered, the new-handler function is called Task performed by handler-function Make more memory available by deleting other dynamically allocated memory and return to operator new to attempt to allocate memory again. Throw an exception of type bad_alloc. Call function abort or exit to terminate the program Example Standard Library Exception Hierarchy Summary An exception is an indication of a problem that occurs during a program's execution Exception handling enables programmers to create programs that can resolve problems that occur at execution Exception handling enables the programmer to remove error-handling code try block define a block of code in which exceptions might occur At least one catch handler must immediately follow a try block Cont. catch handler specifies an exception parameter that represents the type of exception the catch handler can process Point in the program at which an exception occurs is called the throw point When a try block terminates, local variables defined in the block go out of scope Common examples of exceptions are out-of-range array

TỪ KHÓA LIÊN QUAN
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.