Catch Section

Top  Previous  Next

 

A Catch section is used to define commands to be run automatically in the event that an error is thrown elsewhere in the script. It is strongly recommended that you create a Catch section after any Setup Section and Notification Section and before any Finally Section defined in the script.

 

Command Syntax

 

If you wish to create a Catch section, you simply type the word Catch into the script surrounded by square brackets:

 

[Catch]

 

lamp IMPORTANT: The Catch section should follow any Setup or Notification sections and appear before any other sections.

Example

 

This example uses the VarEquals condition to determine if a file has been saved, and if so attempts to delete it:

 

[Setup]

Var:FileName,"C:\MyFile.txt"

Var:FileSaved,False

 

[Catch]

 

;Delete a file created by an earlier command

If:VarEquals,FileSaved,True,DeleteFile:%%FileName%%

 

[Save]

Exec:FileSaver,%%FileName%%

Assign:FileSaved,True

 

 

This is only one way to do this. For example, instead you could could also use the FileExists condition to check whether or not the file actually exists rather than checking the FileSaved variable value.

lamp Important: If any command specified in the Catch section fails, no further commands in that section will be processed.

See Also: Setup Section Notification Section Finally Section User Sections Tasks Section Code Section