![]() If(object2.func() = ERROR) ErrorHandle() If(object1.func() = ERROR) ErrorHandle() The error code approach involves returning a numeric code to indicate the success/failure of a function: ![]() ![]() Let's start the comparison of the two with simple code: We should avoid the first one at all cost although there are lots of examples of libraries that call abort() or exit().īut between (2) and (3), we do not have any agreement on which one is better. In general, there are three ways of handling error conditions: After OS's done with the file, it returns the control to the user process and resume the program execution starting from where it left. If a program wants to open a file, it is not a normal flow, because the user process should transfer the control to OS to read/write the file. Here, the standard control flow means a normal control flow which includes jumps such as loops/if-else or calling a function. Note that we can think of an exception as non-standard control flow such as interrupts or traps(such as break point) or faults. After performing the exceptions, it returns the control to the user process running the program (resume) or it may simply abort the program. The exception is handled by the exception handler. If these things happen, the control will be transferred to the OS from the process running a program. A program may have division by zero, or page fault, or may request more memory than is available, or it may try to open an unavailable file, or it may see values it cannot handle.
0 Comments
Leave a Reply. |