Step-By-Step Guide to Use Throw to Validate an Email Id and Throw Exception Upon Encountering Validation Error
Let's see an example of validating an E-mail Id. The Throw activity ends the execution of the automation process workflow if the E-mail Id is not in the correct format and logs the exception message in the log file of Automation Studio.
To validate the E-mail Id format and log the exception message:
- In the Canvas Tools pane, click Exception Handling to expand the tool and view the associated activities.
- Drag the Try Catch activity and drop on to the Flowchart designer on the Canvas.
- In the Parameter bar, create an In argument, EmailId and an Out argument, ValidationResult of Boolean type to pass the input and store the result of the validation respectively.
- Double click the TryCatch activity block and add the Regex Validator activity as this is the potential step where an exception can occur.
- Click the
(Settings) icon. The Regex Validator Mapping dialog box appears.
- Click Add to set the validator mapping.
- In the Arguments/Variables drop down list, select EmailInput argument defined above.
- From the Validator Type drop down list, select EmailID.
- Click CONFIRM.
- In the Output Mapping list, select ValidationResult argument defined above.
- Add the If Activity and enter Validation = False in the Enter Expression here field.
- In the Then block, add the Throw activity.
- In the Enter Expression field, enter the message The specified Email Id is incorrect in double quotes.
- You can add the activities in the Catch and Finally block as per your requirement to handle the exception or to perform the action when either the Try activity or any required action in the Catch activity completes.
- Save the process.
- Setup the environment and then perform test run. You can assign this process to a robot, if you want to execute the process outside Automation Studio.
As the Email Id specified is not in the correct format, the Throw activity ends the execution and logs the message in the log file of Automation Studio as shown in the below screen shot: