Bird
0
0

You want to run multiple commands but continue even if one fails. Which approach best prevents script failure?

hard📝 Application Q8 of 15
PowerShell - Error Handling
You want to run multiple commands but continue even if one fails. Which approach best prevents script failure?
AUse a single try-catch around all commands without -ErrorAction
BUse if statements to check for errors
CWrap each command in its own try-catch block
DIgnore errors and let script stop
Step-by-Step Solution
Solution:
  1. Step 1: Understand error handling scope

    A single try-catch stops at first error; wrapping each command allows individual error handling.
  2. Step 2: Benefits of multiple try-catch blocks

    This lets script continue running other commands even if one fails.
  3. Final Answer:

    Wrap each command in its own try-catch block -> Option C
  4. Quick Check:

    Multiple try-catch blocks = continue after errors [OK]
Quick Trick: Use separate try-catch blocks to isolate errors [OK]
Common Mistakes:
  • Using one try-catch for all commands
  • Relying on if statements for error handling
  • Ignoring errors causing script to stop

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes