That’s the downside of just pointing people at the Github repository, I suppose. The error handling book isn’t actually published yet; it’s just a very rough first draft (hence the InProg_ at the beginning of its name.)
You’re right about placing that statement in a finally block, although in this case, you really don’t need to change $ErrorActionPreference at all. Any exceptions thrown by calling a .NET method are already considered terminating errors by PowerShell, and will be caught by a try/catch construct regardless of EAP’s setting (even if it’s SilentlyContinue.)
I understand that the setting of the $ErrorActionPreference is not required. I was simply highlighting an issue I thought I saw in the book. Giving an opportunity to discuss it before the book is released.
If I was going to use $ErrorActionPreference I think I would put the “$ErrorActionPreference = ‘Continue’” in a finally block as it could be that the catch exits the script. That said, due to scoping, if I’m exiting the script it might be relevant.
No problem. It’s just that the repo is also a place for authors to collaborate, and right now the error handling book is “on hold” pending me getting time to work on it.