Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Example 1 - Try, Catch, Finally

Image RemovedImage Added

In this example I have setup a simple work flow which will attempt to execute a program by placing a Try Action in the work flow editor and an Execute Program Action as a child of the Try Action. If that fails, the Catch Action's children will then execute, in this example it will run the Tag Build which I've setup to give it the tag "Failed". I've then placed a Finally Action at the end with a Delete Directory Action as its child. The Finally Action will always execute in this situation regardless of the result of the Try or Catch Actions.

...

If you have a series of actions that could possibly fail but you want all of them to run regardless of the previous result and you don't want the build to fail, then you can place a Catch Action after each one. Suppose you want to run two test executables and don't care if the any of them fail but you want both to run regardless. The verbose way of doing this would be to surround each NUnit Action with a Try/Catch. A simpler way is the following.

Image RemovedImage Added

In this example I've placed a Catch Action directly after each NUnit Action. The result is, if the NUinit Action fails, the failure will be caught and subsequently ignored since we haven't given the Catch Action any children actions to execute. In this case, the work flow will fall through to the next NUnit action.

...

The Finally Action can also be used on its own without having a Try or Catch Action associated with it. Using the Finally Action on its own is handy for times when you want to perform an action or actions regardless of the result of the previous action. If there's only one previous action you care about then there's really no point placing it in a Try Action. For example, if you want to use the Execute Program Action which outputs its files to $Workspace$\Output then you may want to put a Finally Action directory after the Execute Program Action and within that Finally Action put a Delete Directory Action which deletes everything in $Workspace$\Output. Doing it this way ensures the Delete Directory Action always runs regardless of the Execute Program Action result and you also save on having to use the Try Action method. Here's what that work flow would look like.

Image RemovedImage Added