Error Handling

Explore how the error handling construct works in Gatling.

We'll cover the following

In the previous lesson, we learned about the different conditional statements that Gatling offers. In this lesson, we will learn about the different ways to handle errors in the Gatling test script.

Gatling provides us ways to gracefully handle the errors and retry the actions on failure using constructs, such as tryMax, exitBlockOnFail, and exitHereIfFailed.

Let’s learn about them in detail.

tryMax

tryMax(times, counterName) {
  chainOfActions
}
tryMax(session => session("times").as[Int], counterName) {
  chainOfActions
}

chainOfActions is expected to succeed as a whole. If an error happens, the user will skip the rest of the chain and start over from the beginning and attempt to retry the given number of times.

times is the maximum number of retry attempts.

counterName is optional.

A sample scenario:

The chain of action is attempted three times, as there is a check failure, whereas the actual HTTP status code is 200, but the expected HTTP status code is 201.

Get hands-on with 1200+ tech skills courses.