Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start a try block in PowerShell.
PowerShell
try [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or square brackets instead of curly braces.
Forgetting to open the block with any symbol.
✗ Incorrect
In PowerShell, a try block starts with the keyword 'try' followed by an opening curly brace '{'.
2fill in blank
mediumComplete the code to catch an exception in PowerShell.
PowerShell
catch [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or curly braces instead of square brackets.
Omitting the exception type brackets.
✗ Incorrect
In PowerShell, the catch block can specify the exception type in square brackets, like [Exception].
3fill in blank
hardFix the error in the finally block syntax.
PowerShell
finally [1] Write-Host "Cleanup done" }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or square brackets instead of curly braces.
Forgetting to open the block with any symbol.
✗ Incorrect
The finally block must start with an opening curly brace '{' to contain the code block.
4fill in blank
hardFill both blanks to complete a try-catch block that writes an error message.
PowerShell
try [1] Write-Host "Trying code" } catch [2] Write-Host "Error caught" }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of curly braces for blocks.
Mixing up exception type syntax.
✗ Incorrect
The try block starts with '{' and the catch block also starts with '{'. The exception type is optional but here omitted.
5fill in blank
hardComplete the code to complete a try-catch-finally block that handles errors and cleans up.
PowerShell
try { Write-Host "Start" } catch {{BLANK_2} Write-Host "Caught error" } finally { Write-Host "Done" }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of curly braces.
Omitting exception type brackets in catch.
✗ Incorrect
Try and finally blocks start with '{'. Catch specifies exception type in '[Exception]' and also uses '{' to open the block.