There are two common parameters for error handling.
-Erroraction and -Errorvariable
To know about common parameters:
Get-Help -Name about_CommonParameters;
if an error occurs while running the script it will save that error in automatic variable
Automatic variable : $error
Error handling is very important when you write scripts. You should know what is happening when the script is running. you could catch errors if the error occurs while running the script
Syntax:
Try
{
}
catch
{
$_
}
Finally
{
}
Put your scripts in Try block and Catch block would catch the errors while running the scripts.
-Erroraction and -Errorvariable
To know about common parameters:
Get-Help -Name about_CommonParameters;
if an error occurs while running the script it will save that error in automatic variable
Automatic variable : $error
Error handling is very important when you write scripts. You should know what is happening when the script is running. you could catch errors if the error occurs while running the script
Syntax:
Try
{
}
catch
{
$_
}
Finally
{
}
Put your scripts in Try block and Catch block would catch the errors while running the scripts.
No comments:
Post a Comment