Home Dashboard Directory Help
Search

Remove-Item always generates system exception except when -ErrorAction SilentlyContinue by baodad1


Status: 

Active


1
1
Sign in
to vote
Type: Bug
ID: 794929
Opened: 7/24/2013 3:17:34 PM
Access Restriction: Public
1
Workaround(s)
view
0
User(s) can reproduce this bug

Description

When remove-item generates an error, there is no way to handle the error in Powershell without the error resulting in a system error that generates red error text on the console, EXCEPT if I add the -ErrorAction SilentlyContinue switch on to it, in which case it behaves like VB's On Error Resume Next, with no indication of failure whatsoever.
Details
Sign in to post a comment.
Posted by baodad1 on 8/7/2013 at 6:53 PM
Is this by design?
I just found this page: http://www.codesmartnothard.com/2011/07/03/HeyPowerShellWhyIsMyTryCatchNotWorking.aspx
Sign in to post a workaround.
Posted by baodad1 on 7/24/2013 at 3:22 PM
Use
if (!$?) {}
to trap Remove-Item exceptions