Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Programming languages without exception-handling facilities, it is common to

ID: 3760702 • Letter: I

Question

In Programming languages without exception-handling facilities, it is common to have most subprograms include an "error" parameter, which can be set to some value representing "OK" or some other value representing "error in procedure." What are at least 3 advantages that a linguistic exception-handling facility like that of Ada has over this method?

In a programming lanuage without exception-handling facilities, we could send an error-handling procedure as a parameter to each procedure that can detect errors that must be handled. What are at least three disadvantages to this method?

Explanation / Answer

>There are several advantages of a linguistic mechanism for handling exceptions, such as that found in Ada, over simply using a flag error parameter in all subprograms. One advantage is that the code to test the flag after every call is eliminated. Such testing makes programs longer and harder to read. Another advantage is that exceptions can be propagated farther than one level of control in a uniform and implicit way. Finally, there is the advantage that all programs use a uniform method for dealing with unusual circumstances, leading to enhanced readability.
> If a parameter is passed, the error status code needs to be checked after each call to a subprogram, obscuring the program logic. Also, the error-handling code needs to be located everywhere that check takes place, further cluttering the program (the code could be placed in one subprogram, or branched to using GOTOs, but neither of these is a clean solution). The exception-handling mechanisms preclude the need for constant checks and also provide a smooth way to share exception-handling code (by propagation).

>There are several disadvantages of sending error handling subprograms to other subprograms. One is that it may be necessary to send several error handlers to some subprograms, greatly complicating both the writing and execution of calls. Another is that there is no method of propagating exceptions, meaning that they must all be handled locally. This complicates exception handling, because it requires more attention to handling in more places.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote