Recall & Review
beginner
What is the purpose of the
try block in PowerShell?The
try block contains code that might cause an error. It lets you test code safely and handle errors if they happen.Click to reveal answer
beginner
What does the
catch block do in a try-catch-finally structure?The
catch block runs only if an error happens inside the try block. It lets you respond to or fix the error.Click to reveal answer
intermediate
Explain the role of the
finally block in PowerShell's try-catch-finally.The
finally block runs after try and catch, no matter what. It is used to clean up or finish tasks like closing files.Click to reveal answer
intermediate
How do you catch specific types of errors in PowerShell?
You can specify the error type in the
catch block, like catch [System.IO.IOException], to handle only that error type.Click to reveal answer
advanced
What happens if an error occurs in the
finally block?If an error happens in
finally, it can stop the script or cause another error. So, keep finally code simple and safe.Click to reveal answer
Which block runs only if an error occurs in the
try block?✗ Incorrect
The
catch block runs only when an error happens inside the try block.What is the main purpose of the
finally block?✗ Incorrect
The
finally block always runs after try and catch, no matter if there was an error or not.How do you specify which error type to catch in PowerShell?
✗ Incorrect
You specify the error type in the
catch block like catch [System.Exception].If no error occurs in
try, which blocks run?✗ Incorrect
If no error happens,
try runs, catch is skipped, and finally runs.What is a good practice for code inside
finally?✗ Incorrect
Keep
finally code simple to avoid causing new errors during cleanup.Describe how try-catch-finally works in PowerShell and why each block is important.
Think about how you handle problems and cleanup in daily tasks.
You got /3 concepts.
Explain how you can catch only specific error types in PowerShell's try-catch.
Imagine sorting mail by type to handle it better.
You got /3 concepts.