Exercise 3: A try/catch/finally Block for Reading a File — Possible Solution ==================================================================== THE CODE ------------------------------ try { Get-Content .\data.txt -ErrorAction Stop } catch { "Couldn't read the file: $($_.Exception.Message)" } finally { "Done" } WHY THIS SATISFIES EACH REQUIREMENT ------------------------------ -ErrorAction Stop on Get-Content ensures a missing or unreadable file produces a genuine terminating error, per this chapter's own central rule, rather than a non-terminating one the catch block would never see. The catch block uses $_.Exception.Message, correctly using $_'s catch-specific meaning (the caught error record) rather than a pipeline object, to build a friendly message. The finally block prints "Done" unconditionally - per this chapter, finally always runs regardless of whether the try block succeeded or the catch block fired, making it the correct place for something that must happen either way. WHY THIS WORKS AS AN ANSWER ------------------------------ It provides working try/catch/finally code that correctly uses -ErrorAction Stop to make the error catchable, correctly uses $_.Exception.Message inside catch, and correctly places the unconditional "Done" message inside finally rather than after the whole block (which wouldn't run if an uncaught error occurred).