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:
“In the very midst of the crowd about this wreck, there were men with carts busily collecting the seaweed which the storm had cast up, and conveying it beyond the reach of the tide, though they were often obliged to separate fragments of clothing from it, and they might at any moment have found a human body under it. Drown who might, they did not forget that this weed was a valuable manure. This shipwreck had not produced a visible vibration in the fabric of society.”
—Henry David Thoreau (18171862)
“Ive never known a Philadelphian who wasnt a downright character; possibly a defense mechanism resulting from the dullness of their native habitat.”
—Anita Loos (18881981)
“U.S. international and security policy ... has as its primary goal the preservation of what we might call the Fifth Freedom, understood crudely but with a fair degree of accuracy as the freedom to rob, to exploit and to dominate, to undertake any course of action to ensure that existing privilege is protected and advanced.”
—Noam Chomsky (b. 1928)