$error is an automatic variable, not supposed to be overwritten. (Many such automatic variables will still allow you to happily overwrite them anyway, but $error is not one of them. It fights back. 😉 )
It could be that this snippet worked back in PowerShell v1 or v2, which is what was current when the two editions of PowerShell In Action were published.