Hi Geert, When a pre-commit trigger throws an exception, the query that triggered it gets that exception (and cannot catch it with a try/catch). The fact that it aborts the update is by design because the pre-commit trigger must complete before the transaction is committed.
I can think of a way of doing this though. The trick here is to make sure the calling main module can catch the exception. So if you xdmp:invoke or xdmp:eval the module that does the insert that triggers the pre-commit trigger, then you can catch the exception to that module (which includes an exception from the pre-commit trigger). Something like the following worked for me, assuming a pre-commit trigger scoped on the "/" directory: (: trigger definition: xquery version "1.0-ml"; import module namespace trgr="http://marklogic.com/xdmp/triggers" at "/MarkLogic/triggers.xqy"; trgr:create-trigger("myTrigger", "Simple trigger example", trgr:trigger-data-event( trgr:directory-scope("/", "1"), trgr:document-content("create"), trgr:pre-commit()), trgr:trigger-module(xdmp:database("test"), "/", "error.xqy"), fn:true(), xdmp:default-permissions() ) :) (: /error.xqy: xquery version "1.0-ml"; fn:error((), "hello") :) xquery version "1.0-ml"; try { xdmp:eval('xdmp:document-insert("/hello.xml", <hello/>)') } catch ($e) { "caught exception " } This should work with an invoke too. -Danny -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Geert Josten Sent: Sunday, November 01, 2009 10:56 PM To: General Mark Logic Developer Discussion Subject: [MarkLogic Dev General] Capturing the exception from a pre-commit trigger Hi, I would like to put some checks in a pre-commit trigger, that throws an exception if something is wrong, preventing updates to be stored if the checks are not fully satisfied. The problem is though, that this trigger is throwing an exception that breaks the main module as well. Is there a way to capture the exception thrown from the pre-commit trigger? Kind regards, Geert Drs. G.P.H. Josten Consultant http://www.daidalos.nl/ Daidalos BV Source of Innovation Hoekeindsehof 1-4 2665 JZ Bleiswijk Tel.: +31 (0) 10 850 1200 Fax: +31 (0) 10 850 1199 http://www.daidalos.nl/ KvK 27164984 De informatie - verzonden in of met dit emailbericht - is afkomstig van Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit bericht kunnen geen rechten worden ontleend. _______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general _______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general
