Raising Exceptions for Actions

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

A recipe fails when the Recipe Framework cannot assign input values to an action, or when the action itself raises an exception. In each case, the Recipe Framework calls any actions that have already been executed, in reverse order. The Recipe Framework calls the Undo method of each action, so you need to write every action in such a way that the Undo method will undo the result of the Execute method.

The Recipe Framework requires the input and output action parameters specified in the Guidance Package configuration file to correspond to properties in the classes that implement the action. Before the Recipe Framework calls Execute on an action object, it attempts to set those properties. If the setting of a property raises an exception (for example, if the name or type of the property is different from what is defined in the configuration file), the Recipe Framework catches the exception and starts the undo process.

An action can also fail internally. For example, a user may try to generate a class in a project with a name of a class that already exists. In a case like this, the action needs to raise an exception. This exception will be caught by the Recipe Framework, which will again start the undo process. The exception will be shown to the user in a dialog box displayed by the Recipe Framework.

Any exception that is thrown from an action is wrapped in ActionExecutionException, which is derived from RecipeExecutionException.

See also

Developing Actions | Writing Action Classes | Obtaining and Using Host Services