You can, if you want to, check the $ErrorActionPreference
variable to see how errors should be handled.
You can read more about this and other preference variables if you do Get-Help about_preference_variables
.
Edit 2014-04-22: Added an example on testing this behaviour
Here's an example of how you can test this:
function Test-Error
{
[CmdletBinding()]
PARAM()
Write-Host "Error action preference is '$ErrorActionPreference'"
Write-Error "This is a test error"
}
Test-Error
Test-Error -ErrorAction SilentlyContinue
Test-Error -ErrorAction Continue
Test-Error -ErrorAction Stop
Write-Host "We shouldn't get here, since last error action was 'Stop'"
This yields the following output:
Error action preference is 'Continue'
Test-Error : This is a test error
At line:12 char:5
+ Test-Error
+ ~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Test-Error
Error action preference is 'SilentlyContinue'
Error action preference is 'Continue'
Test-Error : This is a test error
At line:14 char:5
+ Test-Error -ErrorAction Continue
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Test-Error
Error action preference is 'Stop'
Test-Error : This is a test error
At line:15 char:5
+ Test-Error -ErrorAction Stop
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Test-Error