This is because xtk.session.write doesn't use the connection vCnx. When using the DBEngine class (returned by application.getConnection()), you have to stick with the functions it offers (i.e. execute()). See all functions here: DBEngine (Class)
I tested the below code in a sandbox. If the line 16 is commented, it works well and create a recipient named "hello". If the line 16 is uncommented, then the exception is raised and the recipient is not created.
var vCnx = application.getConnection();
vCnx.execute("INSERT INTO nmsRecipient (iRecipientId, sFirstName) VALUES (123456, 'hello');");
throw new Error('exception here');
createFilter(vCnx); // if commented, the recipient is created, otherwise the SQL transaction is rolled back