The try-catch statements are used as "exception handlers" that can test Deluge scripts for run-time errors, and perform required actions if any errors are found. The exception handler is established by enclosing deluge code, which you think might throw an error, in the Try block. The Try block is immediately followed by a Catch block which contains code to be executed if any errors are thrown in the Try block. For example you can choose to send an email containing the error message, in case of any run-time error, for a clear understanding and the reason behind any failed events. If no errors are found, the Catch block is simply ignored and is not executed.
<code> //Run code here. Enclose Deluge script that might throw an error.
catch(err) //"err" is a variable that holds the error message
<code> //Handle errors here. Write Deluge script to perform any action if errors are found in Try block.
err is a variable that will hold the error message(if any) thrown while executing statements in the Try block.
In this example, we are trying to deliver an SMS after form submission on a particular webpage. The deluge script used to execute this is written in "Try" block. A sendmail task is configured in the "Catch" block to send an email(to the admin) with error details if SMS delivery fails.
resp = postUrl("http://sms.com", formdata);
status = resp.executeXPath("/resp/sms/status/text()");
subject:"Not able to deliver SMS on form submission"
message:"Due to the following error sms is not delivered "+ e.message