Best Practice: It is recommended to avoid empty empty Catch block in a try-catch-(finally) statement.
1 2 3 4 5 6 7 8 |
try { Get-ADUser -Identity AccountNotExist } catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] { } |
Explanation:
Leaving an empty catch block is not considered a good practice because when an error occcurs in the try block, no action is performed on the error.
1 2 3 4 5 6 7 8 |
try { Get-ADUser -Identity AccountNotExist } catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] { Write-Warning -Message 'Account not found' } |