Solution Review: Applying Error Handling
Review the solution of applying error handling to Azure Functions.
We'll cover the following...
Overview
The complete solution is presented in the code widget below:
using System; using Microsoft.Azure.WebJobs; using Microsoft.Extensions.Logging; namespace AzureFunctionApp; public class Functions { [FunctionName("TimerFunction")] [FixedDelayRetry(-1, "00:00:10")] public void TimerWithExceptionHandling([TimerTrigger("0 * * * * *")] TimerInfo timer, ILogger log) { try { if (DateTime.UtcNow.Minute % 2 != 0) throw new InvalidOperationException("Incorrect schedule time."); } catch(InvalidOperationException ex) { log.LogError("Timer execution failed. {Error} {StackTrace}", ex.Message, ex.StackTrace); } log.LogInformation("Timer executed successfully. Next occurrence: {Occurrence}", timer.Schedule.GetNextOccurrence(DateTime.UtcNow)); } }
Complete solution with error handling
Solving the challenge
We perform the ...