I have a PowerShell script containing the following logging function:
function LogError([string] $message, $exception = $null) {…} In a try-catch block, when an exception occurs, I call that logging function like this:
catch { LogError("…", $_.Exception) } In the LogError function, the second argument is always $null. Why?
I couldn't find any documentation that would explain why I cannot use $_.Exception in a function call or that I am supposed to use instead.
Function(Args)The parens are precedence and grouping operators so when you pass your args like this you are passing a single array with 2 elements instead of 2 discrete arguments.