Error Handling
  • Updated on 27 Dec 2018
  • 1 minute to read
  • Contributors
  • Print
  • Comments
  • Share
  • Dark
    Light

Error Handling

  • Print
  • Comments
  • Share
  • Dark
    Light

#ServerlessTips - Azure Functions
Author: Steef-Jan Wiggers Azure MVP

Apply error handling in your Azure Functions to enhance robustness – an obvious choice you would think. However, with functions, you may forget about it as you quickly want to run code in the cloud.

Azure Functions allows you as a developer to integrate with Azure Storage blobs and queues, Service Bus queues, Cosmos DB and a few other Azure services through trigger and bindings. When integrating with these services you may run into errors raised by these services.

Based upon your scenario, you are building a function for your need to consider how to deal with errors. Some triggers provide a retry mechanism and by default retry five-times and after that write a message to a poison queue. These triggers with built-in retry support are:

  • Azure Blob storage
  • Azure Queue storage
  • Azure Service Bus (queue/topic)

Furthermore, other bindings can return exception and errors, which you have to deal handle.

The purest form of applying error handling is adding a try-catch in your function. The “try-catch” will allow you to catch the exception inside the execution of the function.

A good example is available on GitHub and the Reliable Event Processing in Azure Functions article from Jeff Hollan.

Lastly, you can create a Durable Functions solution with Azure Functions. With Durable functions, you apply error handling inside the orchestration function, as exceptions thrown in any activity function is marshalled back to the orchestrator function and thrown as a FunctionFailedException.

For more details on error handling in Durable Functions, read: Handling errors in Durable Functions (Azure Functions)

Always think about the reliability and robustness of your Azure Function. Therefore, consider retry policies and error handling for your Azure Functions!

Was this article helpful?