I want to release all objects if any exception or error occur in running webjob. How do I know if error occurred.Is there any error trigger working with webjob?
How do azure webjobs behave when any error or exception occurs in running webjob?
2.1k Views Asked by Namrata Rawool At
2
There are 2 best solutions below
1

Is there any error trigger working with webjob?
About ErrorTrigger
you could refer to this wiki. You could send email notification if you need or you could execute the method you write. In the doc, you can find some code samples details.
As for exception, you could catch exceptions and handle them with try catch
.
There could be two approaches to handle this:
1) Try/Catch method:- You may trigger a mail or any action in catch block. In catch block you can send the info of the exception you got to your mail account or may even write to any DB table or add it to any queue.
2) Function Filter:- You may user function filter which has function exception filter attribute that is called on any exception situation. You may find the details here: https://github.com/Azure/azure-webjobs-sdk/wiki/Function-Filters
Also their is a piece of code from where you can take the reference:
You may call it by decorating your method with "ErrorHandler" attribute. So, in case of any exception "OnExceptionAsync" function will be called.