Try-catch error handling

This section explains the Try-catch functionality in Quickwork, a crucial feature for robust error handling within journey automation.

Try-catch blocks manage exceptions effectively, ensuring a journey can address potential errors without abrupt termination. This mechanism is essential for handling errors in journeys involving potentially unstable actions, ensuring they remain robust and reliable. By integrating Try-catch blocks, Quickwork ensures that journeys can continue functioning smoothly even when encountering issues, enhancing overall reliability and efficiency in automation processes.

Common use cases for the Try block in journeys

The Try block is typically used to enclose actions that might fail for various reasons such as API limitations, connectivity issues, or data inconsistencies. Here are a few examples of what you might include in a Try block to ensure robust error handling:

  • API requests: Any action that involves sending a request to an external API. For instance, fetching user data from a social media API, submitting forms via web services, or retrieving real-time pricing from a stock market API.
  • Database operations: Actions that perform database queries or updates, especially where there might be a risk of query failure due to syntax errors, connection timeouts, or constraint violations.
  • File operations: Actions that handle file uploads, downloads, reading from or writing to files where there could be issues like file not found, permission denied, or file in use.
  • Data transformation: Complex data manipulation tasks such as parsing JSON, converting data formats (For example, XML to JSON, CSV to Excel), or applying transformations that might fail if the input data is not in the expected format.
  • External service integrations: Any interactions with external services such as sending emails, SMS messages, or notifications where failures could occur due to service downtime or configuration errors.
  • Dynamic content generation: Actions that involve generating content dynamically, such as creating PDF documents or rendering images based on user inputs, which may fail due to invalid input or rendering errors.
  • Handling database downtime: Database If the target database is not ready (downtime or temporary locking of rows due to other queries), add a delay in the Catch block using a scheduler for a few minutes and retry the same insert operation on the target database. Users can auto-retry instead of re-running the transaction that failed due to runtime errors.

By wrapping such actions in a Try block, you can ensure that any errors encountered do not abruptly stop the journey. Instead, control is passed to the Catch block, where you can handle the error gracefully, for example, by logging the error, sending an alert or notification, or attempting a recovery operation. This setup helps maintain the reliability and stability of your automated journeys.

Consider a scenario where you have a Quickwork account configured to automate data transformation tasks. These tasks involve querying a database, converting data formats, and sending notifications. You want to define the journey that automates the process of fetching, transforming, and sending data while ensuring that any errors are promptly reported, enhancing operational efficiency and reliability.

Prerequisites

  • Basic understanding of Quickwork terminologies and familiarity with the platform's GUI.
  • Experience in creating, executing, and managing a Journey effectively from start to finish.
  • If you want to try out this specific use case, you need:
    • Access to a PostgreSQL database for executing SQL queries.
    • Gmail/Gmail Secondary account.
    • Utilities by Quickwork for data transformation.

Building the journey using Try-catch

  1. Set up the trigger: Choose the option New scheduled event via Scheduler by Quickwork. This event is programmed to Start at a specific time and date, based on the Interval set, which facilitates the automation of routine tasks like data updates or sending out regular notifications.

  2. Configure the Try block:

    1. Execute a Custom SQL Query via PostgreSQL: This step runs a SQL query to retrieve fields from a PostgreSQL database.
    2. Convert JSON Data to an Excel Format via Utilities by Quickwork: This step converts the fetched JSON data into an Excel file.
    3. Email Notification: Set up an email notification of the Excel file via Gmail/Gmail Secondary.
  3. Configure the Catch block: An action is configured to send an email via Gmail/Gmail Secondary in case of an error. This email should alert the responsible personnel about the issue, providing an opportunity to address the error proactively.

Testing and executing the journey

  1. Click the Save & Start button to activate the journey. Testing involves scheduling an event via the scheduler to trigger the journey.
  2. Monitor the journey execution to verify that the Try block actions execute successfully and that the Catch block handles any errors as configured.

Troubleshooting

  • Check error messages: Review the error messages captured by the Catch block. These messages can provide crucial insights into what might be going wrong within the Try block. Use these messages to refine the actions that are failing.
  • Monitor logs: Utilize the logging capabilities of Quickwork to monitor what happens before and after an error occurs. Logs can help trace the step-by-step execution of the journey and pinpoint exactly where failures are happening.
  • Connection validity: Ensure that all connections (For example, PostgreSQL, Gmail) used within the journey are active and not expired. Connection issues are a common source of errors in automated journeys.
  • Test with different data sets: Sometimes, errors occur due to specific data inputs. Test the journey with various data sets to ensure robustness against different inputs that might cause the journey to fail. If an error persists, modify the parameters or the structure of the Try block actions based on the insights gained from the above steps. After adjustments, retry the journey to check if the issue is resolved.

✏️ Tips and recommendations

  • Ensure that all potential points of failure within your journeys are wrapped in Try-catch blocks to avoid unexpected terminations and to have fallback actions in case any errors are encountered in the Try block.
  • Review and update the error handling logic regularly to adapt to new errors or changes in external systems (like database schemas or API endpoints).

📚 Additional resources

Journeys with business logic
If condition
If condition using AND/OR operator
If else condition
Stop journey
Foreach loop
Error handling
Scheduler by Quickwork