PowerShell provides two different ways to handle terminating errors: using try-catch-finally, or using trap.
Catching errors
try, catch, and finally
PowerShell 2.0 introduced try-catch-finally as a means of handling terminating errors.
try
A try block must be followed by either one or more catch blocks, a finally block, or both. Each of the following patterns is valid:
try { <script> } catch { <script> } try { <script> } finally { <script> } try { <script> } catch { <script> } finally { <script }
An error occurring within try will...