A. The script stops because the Catch block is missing
B. The error is non-terminating, so Try/Catch does not catch it
C. The script stops because -ErrorAction Stop causes termination without Catch
D. The error is terminating and caught, so script continues after Catch
Solution
Step 1: Analyze -ErrorAction Stop with Try/Catch
Using -ErrorAction Stop makes the error terminating, so Try/Catch can catch it.
Step 2: Understand script flow after Catch
The Catch block runs and outputs 'Caught error', then script continues to print 'Script continues'.
Final Answer:
The error is terminating and caught, so script continues after Catch -> Option D
Quick Check:
Terminating error caught, script continues [OK]
Hint: Try/Catch catches terminating errors with -ErrorAction Stop [OK]
Common Mistakes:
Thinking non-terminating errors trigger Catch
Assuming script stops without Catch block
Confusing error action effects on Try/Catch
5. You want to run a script that tries to get multiple files, but you want it to stop immediately if any file is missing. Which approach correctly enforces this behavior?
hard
A. Use Get-Item with -ErrorAction Stop inside a Try/Catch block to handle errors.
B. Use Get-Item with -ErrorAction Continue and no error handling.
C. Use Get-Item with -ErrorAction SilentlyContinue and log errors later.
D. Use Get-Item without any -ErrorAction parameter.
Solution
Step 1: Identify requirement to stop on missing file
Stopping immediately on error means using terminating errors with -ErrorAction Stop.
Step 2: Use Try/Catch to handle and control flow
Wrapping calls in Try/Catch lets you catch the error and stop or handle it as needed.
Final Answer:
Use Get-Item with -ErrorAction Stop inside a Try/Catch block to handle errors. -> Option A
Quick Check:
Stop errors + Try/Catch = immediate stop [OK]
Hint: Use -ErrorAction Stop with Try/Catch to halt on errors [OK]
Common Mistakes:
Using Continue or SilentlyContinue expecting stop
Not using Try/Catch to handle terminating errors
Ignoring error handling for critical failures
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.