Exercise 2: Why Remove-Item Uses -ErrorAction Stop in the Deletion Step — Possible Solution ==================================================================== WHY -ErrorAction Stop IS NEEDED ------------------------------ Per Chapter 9, most built-in cmdlet errors - including Remove-Item failing on a locked or permission-denied file - are non-terminating by default: PowerShell displays the error and simply continues on to the next statement, without the try/catch actually intercepting anything. -ErrorAction Stop converts that specific Remove-Item failure into a genuine terminating error, which is the only kind try/catch can actually catch. Without it, a failed deletion would just print a red error and move on, and the catch block's own Write-Warning message (meant to tell Dana exactly which file failed and why) would never run at all. WHAT WOULD HAPPEN TO A LOCKED FILE WITHOUT -ErrorAction Stop ------------------------------ A locked file's Remove-Item call would fail with a non-terminating error, PowerShell would display a generic red error message, and the loop would continue on to the next file - the catch block's own friendlier Write-Warning ("Couldn't delete $($file.FullPath): ...") would never execute, and the finally block's own "Finished handling" message would still run regardless, potentially giving Dana a misleading impression that the file was handled cleanly when it wasn't actually confirmed deleted. WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly explains that Remove-Item's errors are non-terminating by default and that -ErrorAction Stop is required to make catch actually intercept them, and correctly describes the real consequence (the catch block's own diagnostic message never firing) if -ErrorAction Stop were omitted.