Bixby Developer Center

Guides
References

Input Validation and Error Handling

This capsule demonstrates how to validate input and handle errors in your actions.

Download Capsule

Note

Because you cannot submit a capsule with the example namespace, in order to test a sample capsule on a device, you must change the id in the capsule.bxb file from example to your organization's before making a private submission.

For example, if your namespace is acme, change example.errorHandling to acme.errorHandling.

Input Validation

Before you execute your implemented actions, you can try to pre-empt potential issues by validating input.

This capsule demonstrates how to check an action's input, and also how to handle any invalid input using several methods.

To see them in action, start the conversation with the utterance "Validate input" in the Simulator. This calls the ValidateInputs.model.bxb file. You can then observe what happens in various instances:

  • "101" causes a halt response, which stops execution of the capsule and displays a message.

  • "42" causes a replan response, which specifies a new intent and goal of the action with the new input.

  • "19" causes a prompt response, which displays an error message to users and asks them to re-enter a valid number.

  • "9" causes a successful response.

Video Tutorial: Validating Input in Bixby

Error Handling

In Bixby Language, errors thrown by JavaScript can be caught with a throws block that specifies an error type along with an on-catch block that specifies an effect used for handling the error.

This capsule demonstrates several error-handling effects. To see them in action, enter the example utterance in the Simulator.

  • drop drops an input (the integer specified below) and re-executes the plan.

    "Show drop input 1 example"

    See GetResultDrop.model.bxb and GetResultDrop.js.

  • halt stops execution of the plan.

    "Show halt example"

    See GetResultHalt.model.bxb and GetResultHalt.js.

  • replan specifies a new intent and goal in the on-catch block.

    "Show replan example"

    See GetResultReplan.model.bxb and GetResultReplan.js. The replan specifies a new intent with a goal of Result and a route of GetResult; see GetResult.model.bxb and GetResult.js.

Other effects that can be used in error handling include prompt, replace, unlock, and flag-as-off-topic. These are implemented in similar fashion. For details about their operation, see the effects documentation.

Video Tutorial: Error Handling in Bixby