0
0
PowerShellscripting~10 mins

Try-Catch-Finally in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a try block in PowerShell.

PowerShell
try [1]
Drag options to blanks, or click blank then click option'
A<
B[
C(
D{
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or square brackets instead of curly braces.
Forgetting to open the block with any symbol.
2fill in blank
medium

Complete the code to catch an exception in PowerShell.

PowerShell
catch [1]
Drag options to blanks, or click blank then click option'
A(Exception)
B[Exception]
C{Exception}
D<Exception>
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or curly braces instead of square brackets.
Omitting the exception type brackets.
3fill in blank
hard

Fix the error in the finally block syntax.

PowerShell
finally [1] Write-Host "Cleanup done" }
Drag options to blanks, or click blank then click option'
A{
B[
C(
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or square brackets instead of curly braces.
Forgetting to open the block with any symbol.
4fill in blank
hard

Fill 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'
A{
B[Exception]
D(Exception)
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of curly braces for blocks.
Mixing up exception type syntax.
5fill in blank
hard

Complete 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'
A{
B[Exception]
D(
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of curly braces.
Omitting exception type brackets in catch.