Restarts Separate Mechanism From Policy
Condition handling moreover provides a separation of mechanism from policy. Restarts provide various possible mechanisms for recovering from error, but do not select which mechanism is appropriate in a given situation. That is the province of the condition handler, which (since it is located in higher-level code) has access to a broader view.
An example: Suppose there is a library function whose purpose is to parse a single syslog file entry. What should this function do, if the entry is malformed? There is no one right answer, because the same library could be deployed in programs for many different purposes. In an interactive log-file browser, the right thing to do might be to return the entry unparsed, so the user can see it—but in an automated log-summarizing program, the right thing to do might be to supply null values for the unreadable fields, but abort with an error, if too many entries have been malformed.
That is to say, the question can only be answered in terms of the broader goals of the program, which are not known to the general-purpose library function. Nonetheless, exiting with an error message is only rarely the right answer. So instead of simply exiting with an error, the function may establish restarts offering various ways to continue—for instance, to skip the log entry, to supply default or null values for the unreadable fields, to ask the user for the missing values, or to unwind the stack and abort processing with an error message. The restarts offered constitute the mechanisms available for recovering from error; the selection of restart by the condition handler supplies the policy.
Read more about this topic: Exception Guarantees, Exception Handling in Software, Condition Systems
Famous quotes containing the words separate, mechanism and/or policy:
“As the two boys walked sorrowing along, they made a new compact to stand by each other and be brothers and never separate till death relieved them of their troubles. Then they began to lay their plans. Joe was for being a hermit, and living on crusts in a remote cave, and dying, some time, of cold, and want, and grief; but after listening to Tom, he conceded that there were some conspicuous advantages about a life of crime, and so he consented to be a pirate.”
—Mark Twain [Samuel Langhorne Clemens] (18351910)
“When one of us dies of cancer, loses her mind, or commits suicide, we must not blame her for her inability to survive an ongoing political mechanism bent on the destruction of that human being. Sanity remains defined simply by the ability to cope with insane conditions.”
—Ana Castillo (b. 1953)
“While I am in favor of the Government promptly enforcing the laws for the present, defending the forts and collecting the revenue, I am not in favor of a war policy with a view to the conquest of any of the slave States; except such as are needed to give us a good boundary. If Maryland attempts to go off, suppress her in order to save the Potomac and the District of Columbia. Cut a piece off of western Virginia and keep Missouri and all the Territories.”
—Rutherford Birchard Hayes (18221893)