<trycatch>

[This is preliminary documentation and subject to change.]

Executes a set of tasks, and optionally catches a build exception to allow recovery or rollback steps to be taken, or to define some steps to be taken regardless if the tasks succeed or fail, or both.

The tasks defined in the <try> block will be executed in turn, as they normally would in a target.

If a <catch> block is defined, the tasks in that block will be executed in turn only if one of the tasks in the <try> block fails. This failure will then be suppressed by the <catch> block.

The message associated with the failure can also be caught in a property for use within the <catch> block. The original contents of the property will be restored upon exiting the <catch> block.

If a <finally> block is defined, the tasks in that block will be executed after the tasks in both the <try> and <catch> blocks have been executed, regardless of whether any task fails in either block.

Parameters

Attribute Type Description Required
failonerror bool Determines if task failure stops the build, or is just reported. The default is true. False
if bool If true then the task will be executed; otherwise, skipped. The default is true. False
unless bool Opposite of if. If false then the task will be executed; otherwise, skipped. The default is false. False
verbose bool Determines whether the task should report detailed build log messages. The default is false. False

Nested Elements:

<try>

The tasks in this block will be executed as a normal part of the build script.

Executes embedded tasks in the order in which they are defined.

Parameters

AttributeTypeDescriptionRequired
failonerrorbool Determines if task failure stops the build, or is just reported. The default is true. False
ifbool If true then the task will be executed; otherwise, skipped. The default is true. False
unlessbool Opposite of if. If false then the task will be executed; otherwise, skipped. The default is false. False
verbosebool Determines whether the task should report detailed build log messages. The default is false. False

</try>

<catch>

The tasks in this block will be executed if any task in the try block fails.

Parameters

AttributeTypeDescriptionRequired
propertystring Defines the name of the property to save the message describing the failure that has been caught. False
failonerrorbool Determines if task failure stops the build, or is just reported. The default is true. False
ifbool If true then the task will be executed; otherwise, skipped. The default is true. False
unlessbool Opposite of if. If false then the task will be executed; otherwise, skipped. The default is false. False
verbosebool Determines whether the task should report detailed build log messages. The default is false. False

</catch>

<finally>

The tasks in this block will always be executed, regardless of what happens in the try and catch blocks.

Executes embedded tasks in the order in which they are defined.

Parameters

AttributeTypeDescriptionRequired
failonerrorbool Determines if task failure stops the build, or is just reported. The default is true. False
ifbool If true then the task will be executed; otherwise, skipped. The default is true. False
unlessbool Opposite of if. If false then the task will be executed; otherwise, skipped. The default is false. False
verbosebool Determines whether the task should report detailed build log messages. The default is false. False

</finally>

Examples

Requirements

Assembly: NAnt.Contrib.Tasks (0.92.4495.0)