【发布时间】:2022-06-22 22:20:32
【问题描述】:
我有一个包含以下日志记录功能的 PowerShell 脚本:
function LogError([string] $message, $exception = $null) {…}
在 try-catch 块中,当发生异常时,我会这样调用该日志记录函数:
catch { LogError("…", $_.Exception) }
在LogError 函数中,第二个参数始终是$null。为什么?
我找不到任何文档来解释为什么我不能在函数调用中使用 $_.Exception 或者我应该使用它。
【问题讨论】:
标签: powershell powershell-7.0 powershell-7.2