Try catch error logging not working

Hello experts,

In the following script the try catch is not producing any output. The $Error[0].Exception.Message shows the last error and the console displays numerous errors but nothing is being written to the Add-Content file. Looks like it should work, but alas it is not. Would appreciate some assistance in removing my blindness

#Parm(
##Create prompts - pending
$Foo_Path="\\david\wvus\Advancement"
$Out_Path="David_wvus"
#[string]$Foo_Path = "\\david\backups"
#[string]$OutPath = "David_backups'
#[Parameter(Mandatory,HelpMessage = "Foo_Path enter the folder path to be scanned e.g. \\david\backups and the Out_Path variable which identifies the output file e.g. david_backups")]
#Build prompts - pending
#)

$ErrorLog = @()

$FolderPath = Get-Childitem -Directory -Path $Foo_Path -Recurse -Force
$Report = @()
Foreach ($Folder in $FolderPath) {
$Acl = Get-Acl -Path $Folder.FullName
  
     
                    
        Try { 
          
            $acl = Get-ACL -Path $folder.FullName -ErrorAction Continue            
                    
        } Catch {   
            $ErrorLog = "Path Name: {0} - Error {1} -f $folder",  $Error[0].Exception.Message      
             Add-Content -Path D:\PowerShell_temp\foo_test_errors.txt -Value $ErrorLog
        }   
    
    }  

      Foreach ($Folder in $FolderPath) {
    $Acl = Get-Acl -Path $Folder.FullName
    foreach ($Access in $acl.Access)
        {
            $Properties = [ordered]@{'FolderName'=$Folder.FullName;'ADGroup or User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
            $Report += New-Object -TypeName PSObject -Property $Properties
        } 
         
   
    
}
$Report | Export-Csv -path "D:\powershell_temp\$($Out_Path)_Folder_permissions_get-acl_dir_psobject_get_childitem_add_line_to_variable_foreach_loop_new_object.csv"

I’m seeing a couple things that could make things tricky for you here.

One, you’re using -ErrorAction Continue. try/catch only works on terminating errors, so you need -ErrorAction Stop.

Two, I think you might have a typo in your log line:

$ErrorLog = "Path Name: {0} - Error {1} -f $folder", $Error[0].Exception.Message

I think that last quote should be back just before the -f?

Hello Joel,
You were spot on, great catch on the typo and the reminder to use -ErrorAction Stop

Thanks alot!!

Norm