February 2019
Intermediate to advanced
626 pages
15h 51m
English
One of the challenges of writing error handling is determining whether the error is terminating or non-terminating.
A possible solution is to force all errors to be terminating by setting ErrorActionPreference to Stop.
Setting ErrorActionPreference to Stop is equivalent to adding -ErrorAction Stop to every command that supports it.
When exploring nesting try-catch-finally, the following example was used:
try {
Connect-Server
Get-ManagementObject | ForEach-Object {
try {
$_ | Set-ManagementObject -Property 'NewValue'
} catch {
Write-Error -ErrorRecord $_
} finally {
$_
}
}
} catch {
throw}
Setting ErrorActionPreference to Stop would remove the need to set an ErrorAction parameter on each of the commands (if ...
Read now
Unlock full access