Skip to main content
OnCommand Workflow Automation 5.1

Guidelines for error handling

Contributors

You must be aware of the guidelines for error handling when writing a PowerShell or Perl script for OnCommand Workflow Automation (WFA).

PowerShell error handling

Guidelines Example

Common parameters added to cmdlets by PowerShell runtime include error handling parameters such as ErrorAction and WarningAction:

  • The ErrorAction parameter determines how a cmdlet should react to a non-terminating error from the command.

  • The WarningAction parameter determines how a cmdlet should react to a warning from the command.

  • Stop, SilentlyContinue, Inquire, and Continue are the valid values for the ErrorAction and WarningAction parameters.

For more information, you can use the Get-Help about_CommonParameters command in PowerShell CLI.

ErrorAction: the following example shows how to handle a non-terminating error as a terminating error:

New-NcIgroup-Name $IgroupName-Protocol $Protocol-Type$OSType-ErrorActionstop

WarningAction

New-VM-Name $VMName-VM $SourceVM-DataStore$DataStoreName-VMHost$VMHost-WarningActionSilentlyContinue

Use the general “try/catch” statement if the type of the incoming exception is unknown.

try
{
"In Try/catch block"
}
catch
{
"Got exception"
}

Use the specific “try/catch” statement if the type of the incoming exception is known.

try
{
"In Try/catch block"
}
catch[System.Net.WebExceptional], [System.IO.
IOException]
{
"Got exception"
}

Use the “finally” statement to release resources.

try
{
"In Try/catch block"
}
catch
{
"Got exception"
}
finally
{
"Release resources"
}

Use PowerShell automatic variables to access information about exceptions.

try
{
Get-WFALogger -Info -message $("Creating
Ipspace: " + $Ipspace)
New-NaNetIpspace-Name $Ipspace
}
catch
{
Throw "Failed to create Ipspace. Message:
" + $_.Exception.Message;
}

Perl error handling

Guidelines Example

Perl does not include native language support for try/catch blocks. Use eval blocks for checking and handling errors. Keep eval blocks as small as possible.

eval {

$wfa_util->sendLog('INFO',
"Quiescing the relationship :
$DestinationCluster://$DestinationVserver
/$DestinationVolume"
    );
$server->snapmirror_quiesce(
'destination-vserver' => $DestinationVserver,
'destination-volume'  => $DestinationVolume
    );
$wfa_util->sendLog('INFO', 'Quiesce operation
started successfully.');
};

$wfa_util->checkEvalFailure(
"Failed to quiesce the SnapMirror relationship
$DestinationCluster://$DestinationVserver
/$DestinationVolume",
    $@
);