When trapping an error, try to use -ErrorAction Stop on cmdlets to generate terminating, trappable exceptions.