Trap Block {} is not trapping error from a Move-Item RRS feed

  • Question

  • I put a TRAP Block at the front of my scripts to trap all errors so I can send emails, etc (or at least I thought it would trap all errors).  My script was executing and I was issuing a Move-Item statement.  The Move Item statement failed and dumped the error to the ISE output window and then continued to the next statement without going to my Trap Block:

    Move-Item : The process cannot access the file because it is being used by another process.

    What am I missing with the Trap statement - does it not trap ALL errors?  I know it is working because just prior to this it trapped a problem with the same Move-Item statement that had a null parameter.

    • Moved by Bill_Stewart Monday, October 2, 2017 9:51 PM Unanswerable drive-by question
    Thursday, August 24, 2017 6:18 PM


  • Trap is not longer used.  Use Try/Catch or other error methods.

    help about_try_catch

    Apparently you are using an ole PS 1 book to learn PowerShell. Get a newer book.


    • Marked as answer by dcybela Tuesday, October 3, 2017 12:34 PM
    Thursday, August 24, 2017 6:24 PM