Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure函数未在Push OutputBinding中使用Stop ErrorAction引发终止错误_Azure_Powershell_Azure Functions - Fatal编程技术网

Azure函数未在Push OutputBinding中使用Stop ErrorAction引发终止错误

Azure函数未在Push OutputBinding中使用Stop ErrorAction引发终止错误,azure,powershell,azure-functions,Azure,Powershell,Azure Functions,我试图构建一个简单的try-catch语句,如下所示,但是catch块永远不会被执行 试试看{ Push OutputBinding-ErrorAction Stop-Name outputQueueItem-Value$对象 } 抓住{ 写入错误“捕获错误” #捕获错误的代码 } 问题是azure函数没有抛出预期的错误作为终止,除了我有ErrorAction Stop参数之外。因此,catch代码永远不会执行 输出日志: [8/18/2020 9:42:11 PM] INFORMATIO

我试图构建一个简单的try-catch语句,如下所示,但是catch块永远不会被执行

试试看{
Push OutputBinding-ErrorAction Stop-Name outputQueueItem-Value$对象
} 
抓住{
写入错误“捕获错误”
#捕获错误的代码
} 
问题是azure函数没有抛出预期的错误作为终止,除了我有
ErrorAction Stop
参数之外。因此,
catch
代码永远不会执行

输出日志:

[8/18/2020 9:42:11 PM] INFORMATION: 00:00:09.9511800
[8/18/2020 9:42:11 PM] Executed 'Functions.Monitor' (Failed, Id=6bf398bd-de2b-460f-a44b-db9838feff3f)
[8/18/2020 9:42:11 PM] System.Private.CoreLib: Exception while executing function: Functions.Monitor. Microsoft.WindowsAzure.Storage: Messages cannot be larger than 65536 bytes.
错误是预期的,但是,catch代码块从未执行

运行时信息:

Azure Functions Core Tools (3.0.2630 Commit hash: beec61496e1c5de8aa4ba38d1884f7b48233a7ab)
Function Runtime Version: 3.0.13901.0

我还尝试更改变量
$ErrorActionPreference=“Stop”
,但它也不起作用。

您的脚本无法捕获此异常,因为它发生在脚本完成之后。
Push OutputBinding
命令不会直接将数据写入Azure存储。相反,它只是将其存储在一个内部数据结构中,实际写入Azure存储是在函数完成后进行的

另见:


解决方法是将脚本更改为直接写入Azure存储,而不是调用
Push OutputBinding
,这样您就可以实现自己的错误处理。

如果
$ErrorActionPreference='Stop'
写入错误“Catching error”
将中止执行
catch
块,避免从内部抛出错误(至少在您完成错误处理之前)@MathiasR.Jessen顺便说一句,您的预订com职业链接已失效;)@MathiasR Jessen谢谢你的贡献我不知道。但是,在上面共享的示例代码中,当ErrorAction停止时,这不应该发生,它仅在命令级别,并且$ErrorActionPreference是continue,不会在catch@ErickGuillen对的它不应该对
Continue
作为首选项变量产生影响-但我怀疑Azure函数脚本运行程序可能对发出的错误做出反应并中止执行?这只是猜测,但也许值得一试?@MathiasR.Jessen我只是试了一下。即使使用
$ErrorActionPreference='Stop'
,它也会在try函数中生成错误代码后继续执行,并且从不触发捕获。我想Azure Function Runner可能有点奇怪