Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Access denied exception is not catched

$
0
0

Within a for-each block, I use the following powershell code to analyze file paths:

  $path = "\\server\" + $fileName
  try{
    test-path -path $path;
    $%variable.Length
  }
  catch
  {
    write-host "catched " $_.Exception
  }

If $path points to a path where I get an access denied exception, the result is as if there is no try-catch block, i.e.

1. the exception is given in red and without the initial "catched " from my catch block and

2. the result of test-path evaluation ("False") and of the following lines in the try block is also displayed.

In order to check wether whatever is wrong with my try catch block, I've added the line with "$%variable.Length". This exception is caught always, i.e. I always see the output of my catch block.

Can someone please explain and help?

Txs!


 

Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>