The try...catch option

You can start the try...catch option from the BlueParq Designer.

BlueParq Designer

  1. Press the right mouse button, the BlueParq Radial Menu will present itself.

  1. Press the Add try...catch button

Result in the BlueParq Designer

  1. You can now connect three blocks to the try...catch block:
    1. Try: here you add the PowerShell code which can generate an exception
    2. Catch: here you can catch the exception and continue your PowerShell script
    3. Final: Sometimes you don’t need to handle an error but still need some code to execute if an exception happens or not.
  2. In our example we will try to read a file from a network share which does not exist, this will generate an exception.
  3. We will Catch the exception and generate a message.
  4. Finally we will send the Final message.
  5. Press the right mouse button, the BlueParq Radial Menu will present itself.
  6. Choose the Add script blockand double click on the just created block.
  7. Add the following PowerShell code to it:  [System.IO.File]::ReadAllText( '\\test\share\file_not_exist.log')
  8. Connect the script block to the top connector of the try...catch block.
  9. Press the right mouse button, the BlueParq Radial Menu will present itself.
  10. Press the Add cmdlet call button and press Echo in the search field. Also checkout the cmdlet wizard tutorial here.
  11. Press Echo under Alias and press Next.
  12. Make sure you add $_.Exception.ToString() in the InputObject text box.
  13. Press Finish and connect the cmdlet block to the middle connector of the try...catch block.
  14. Press the right mouse button, the BlueParq Radial Menu will present itself.
  15. Press the Add cmdlet call button and press Echo in the search field. Also checkout the cmdlet wizard tutorial here.
  16. Press Echo under Alias and press Next.
  17. Make sure you add Final in the InputObject text box.
  18. Press Finish and connect the cmdlet block to the lowest connector of the try...catch block.

Result in the BlueParq Editor

# The Try Catch block
Try
{
 # Something will go wrong here
 [System.IO.File]::ReadAllText( '\\test\share\file_not_exist.log')
}
Catch
{
 # Show the exception message
 Microsoft.PowerShell.Utility\Write-Output -InputObject $_.Exception.ToString()
}
Finally
{
 # Final block
 Microsoft.PowerShell.Utility\Write-Output -InputObject 'Final'
}

Result in PowerShell

Was this article helpful?
0 out of 0 found this helpful