Posts

Showing posts with the label ErrorAction

Error Handling in PowerShell

Image
A good practice while working on any script is to have a mechanism for error handling. Though it may take a little bit of additional time, its rewards are priceless. Before moving to Error handling in PowerShell, first go through what type of errors we may encounter. Error Types There are two types of errors that can be occurred during script execution.  Terminating  Non-terminating  As the name implies, terminating error will stop the program from further execution, whereas a non-terminating error will not stop the execution. An example of terminating error would be a syntax error whereas an example of non-terminating error would be file/path not found. Terminating errors can be caught and handled while Non-terminating errors cannot be caught by try-catch block. Examples:  Terminating error: Script execution halted when error occurred. Non-terminating error:  Write-Host "Still running" executed even after error occurred. Convert Non-terminating errors into Term...