您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

处理 Azure Functions 绑定错误Handle Azure Functions binding errors

Azure Functions 触发器和绑定与各种 Azure 服务进行通信。Azure Functions triggers and bindings communicate with various Azure services. 与这些服务集成时,可能会遇到来源于底层 Azure 服务 API 的引发错误。When integrating with these services, you may have errors raised that originate from the APIs of the underlying Azure services. 尝试使用 REST 或客户端库通过函数代码与其他服务进行通信时,也可能会发生错误。Errors can also occur when you try to communicate with other services from your function code by using REST or client libraries. 若要避免数据丢失并确保函数的行为正常,请务必处理来自任一源的错误。To avoid loss of data and ensure good behavior of your functions, it is important to handle errors from either source.

以下触发器具有内置重试支持:The following triggers have built-in retry support:

默认情况下,这两种触发器最多重试五次。By default, these triggers are retried up to five times. 第五次重试后,这些触发器会将消息写入到一个特殊的有害队列After the fifth retry, these triggers write a message to a special poison queue.

对于其他 Functions 触发器而言,函数执行期间发生错误时没有内置重试机制。For the other Functions triggers, there is no built-in retry when errors occur during function execution. 为了防止在函数中发生错误时触发器信息丢失,我们建议你在函数代码中使用 try-catch 块捕获任何错误。To prevent loss of trigger information should an error occur in your function, we recommend that you use try-catch blocks in your function code to catch any errors. 发生错误时,触发器会将传入函数的信息写入到特殊的“有害”消息队列。When an error occurs, write the information passed into the function by the trigger to a special "poison" message queue. Blob 存储触发器也使用此方法。This approach is the same one used by the Blob storage trigger.

这样,可以捕获因出错可能会丢失的触发器事件,并在稍后通过其他函数使用存储的信息重试处理有害队列中的消息。In this way, you can capture trigger events that could be lost due to errors and retry them at a later time using another function to process messages from the poison queue using the stored information.

有关 Functions 所支持各种服务的所有相关错误主题链接,请参阅 Azure Functions 错误处理概述主题的绑定错误代码部分。For links to all relevant error topics for the various services supported by Functions, see the Binding error codes section of the Azure Functions error handling overview topic.