Bird
0
0

How can you re-throw the caught error inside a catch block preserving the original error message in PowerShell?

hard📝 Application Q9 of 15
PowerShell - Error Handling
How can you re-throw the caught error inside a catch block preserving the original error message in PowerShell?
Athrow 'Error occurred again'
Bthrow $_
Cthrow
Dthrow $error[0]
Step-by-Step Solution
Solution:
  1. Step 1: Understand error variable in catch

    Inside catch, $_ holds the current error object.
  2. Step 2: Re-throwing the original error

    Using throw $_ re-throws the caught error preserving its message and details.
  3. Final Answer:

    throw $_ -> Option B
  4. Quick Check:

    Use throw $_ to re-throw caught error [OK]
Quick Trick: Use throw $_ to re-throw caught error [OK]
Common Mistakes:
  • Using throw without argument loses error info
  • Throwing a new string loses original error
  • Using $error[0] may not be current error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes