Bird
0
0

What will be the output of this PowerShell script?

medium📝 Command Output Q13 of 15
PowerShell - Error Handling
What will be the output of this PowerShell script?
try {
  Get-Item 'C:\nonexistentfile.txt'
} catch {
  Write-Output 'File not found, continuing script.'
}
Write-Output 'Script finished.'
AGet-Item : Cannot find path 'C:\nonexistentfile.txt' because it does not exist.
BFile not found, continuing script. Script finished.
CScript finished.
DFile not found, continuing script.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze try block

    Get-Item tries to get a file that does not exist, causing an error.
  2. Step 2: Catch block runs

    The catch block catches the error and outputs 'File not found, continuing script.'
  3. Step 3: Script continues

    After catch, the script outputs 'Script finished.'
  4. Final Answer:

    File not found, continuing script. Script finished. -> Option B
  5. Quick Check:

    Catch handles error, script continues = B [OK]
Quick Trick: Catch block output runs, then script continues [OK]
Common Mistakes:
  • Expecting script to stop on error
  • Ignoring catch block output
  • Thinking only last output prints

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes