try/catch block on its own won’t work as expected with Tasks. Internally runTask() throws some special errors to control flow execution. This is necessary to deal with resumability, serverless timeouts, and retrying Tasks.
If this function returns true you must rethrow the error. If it returns false you can handle the error as you normally would.
How to catch errors inside run()
You have two options:
- Use a regular
try/catchblock andisTriggerError()as documented on this page. - Use the io.try() function.
Parameters
The error to check.
Returns
true if the error is a Trigger Error, false otherwise.You must rethrow the error if this function returns true.
