Powershell Errors


These page we will see error types, the $error variable, try/catch blocks and error action preferences in powershell

Two Types of errors :
1. Terminating Error
2. Non-Terminating Error

While in Powershell script execution, either type of error occurs during execution from above mentioned types, it is logged to a global variable called $error.
$error is a collection of PowerShell Error Objects.
$error is nothing but arraylist.
you can fire below query to check the type
$error.GetType()
You can travers to all errors with the most recent error at index 0.
Lets fire any cmdlet which doesn't exits
XYZ
$error.Count
$error[0].Exception
$error[0] | gm

Try/Catch/Finally Blocks:

The Try, Catch, and Finally statements allow us to control script flow when we encounter errors. The statements behave similar to the statements of the same name found in C#, Java and other languages.

Example

try
{
XYZ
}
Catch
{
$error[0].Exception
}
Finally
{
$error[0].Exception
}

Copy and Try it

TO BE CONTINUED..