4

I can’t find any 100% answer relating to what happens when an exception occurs during a timer function app.

I have a azure timer function app that then triggers a http function app. Within the http function app an error could happen. I currently log the error and throw. However if I am throwing the error then will the application stop / will the timer function app stop executing until error has been resolved?! I would want my app to continue to run.

Can anyone provide an answer on what happens when throwing exceptions within function app / timer function app? Thanks

3
  • just wrap the code in a try catch block Commented Jul 18, 2020 at 16:19
  • I am doing that. I’m logging it and throwing exception. I’m working out because I’m throwing exception will it then stop the application i.e end the process? As wouldn’t want that to happen within a scheduled timer function app. Don’t wanna keep resetting the timer every time an exception has happened! Or is azure function app cleverly enough to keep to timer still after exception?! Commented Jul 18, 2020 at 16:30
  • @Paul was your question answered? Please accept an answer if you feel your question was resolved, or add additional details if you think something is missing. Commented Jul 26, 2020 at 14:52

1 Answer 1

3

The function will be triggered again when it is next due.

Source: I just set up a Azure Function with a timer trigger set to run every 15s. It contained nothing but throw Exception();. It was called multiple times, even though it threw an Exception. I recommend you try it out yourself to get a feeling for it.

PS: If you have logging set up correctly, you will not even need to log a throw - Azure Functions automatically log all unhandled exceptions.

 [FunctionName("TriggerFunction")] public void Run([TimerTrigger("0/15 * * * * *")]TimerInfo myTimer, ILogger log) { log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}"); throw new Exception("boom"); } 
Sign up to request clarification or add additional context in comments.

2 Comments

It is also not clear to me, if I it is best practice to re-throw the error in the catch block or not re-throw the error, as it is a Timer function.
The function runtime will log the exceptions if you do not catch them at all. If you are catching them and have handled them sufficiently that you still want the execution to be logged as successful, then do not re-throw them, if you are doing your own logging but want the azure logs to show failure for the execution, then you should re-throw. It is as simple as do you want the logs to show a success or failure for each individual execution, this is not different because you are using a timer trigger than any other trigger.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.