I wrote a javascript to invoke after a document is created in a folder (through the rule). In this script, I tried to send an email.
I put "mail.execute(document)" in the try block, so that it can catch the exception when sending an email (like connection issue to SMTP server, or email address error etc).
After an error happens when sending the mail, the catch statements get hit as expected. However looks like the script still returns error so that I got the error message of "Exception from executeScript - redirecting to status template error: Transaction silently rolled back because it has been marked as rollback-only". The document is still created after this error message though.
On the other hand, if I inject some other exception (such as null object access) into the try block, the exception is catched and no error message returned when creating a document.
What's the problem in catching the excepting when sending the mail?
The javascript code is like below (I removed some unrelated codes)
var mail = actions.create("mail");
mail.parameters.html = "html";
mail.parameters.to = "b@example.com";
mail.parameters.template = search.findNode("workspace://SpacesStore/87d845a1-1639-4de8-b14a-b7c0add7d559");
mail.parameters.subject = "Title";
mail.parameters.from = "a@example.com";
try
{
mail.execute(document); // if comment this line but un-comment next two lines, the exception can be catch
// and every thing fine after the script completes.
//var a=null;
//a.set("abc");
logger.warn ("Email sent.");
} catch (err)
{
logger.warn ("Mail sent failed. Errormsg: " + err.message);
}