Updates within the body of the try will be abandoned; updates before or after will be kept. That is, as long as they are catchable exceptions. If you get an exception in the commit of the whole transaction, all transactions will be lost.
That's as far as updates go. Some side-effects are not transactionally protected, such as writing to a log file. //Mary On Mon, 11 Dec 2017 05:17:00 -0800, Florent Georges <[email protected]> wrote: > Hi, > > I would like to have a confirmation about the handling of side effects > (that is, everything related to MVCC) in the context of try/catch. I > always thought that "whatever was executed in a try clause" before an > error > is raised was going to be kept if the error is caught. > > I know there is an incertainty WRT the order of execution, but still, I > thought some DB modifications called in the try clause could be kept in > case the error is caught. > > Here is an example that tries to replicate the problem, using a recursive > function to beat the optimiser (full code at the end of this email): > > local:side-effect('before'), > try { > local:recurse(('one', 'two')) > } > catch * { > 'Caught error in main module' > }, > local:side-effect('after') > > In the above example, the result is that both /before.xml and /after.xml > are created, but not /one.xml (the creation is called during the first > iteration of the recursive function though). > > All the tests I made have the same result: all DB modifications in the > try > clause are discarded in case an error is raised (regardless it is caught > or > not). > > I could not find a definitive answer in the doc. Is this guaranteed? > > Full example: > > xquery version "3.0"; > > declare namespace xdmp = "http://marklogic.com/xdmp"; > > declare function local:side-effect($name as xs:string) > { > xdmp:document-insert( > '/' || $name || '.xml', > <hello>{ $name }</hello>) > }; > > declare function local:recurse($names as xs:string) > { > if ( fn:count($names) eq 1 ) then ( > fn:error((), 'Climb the stack...') > ) > else ( > local:side-effect(fn:head($names)), > local:recurse(fn:tail($names)) > ) > }; > > local:side-effect('before'), > try { > local:recurse(('one', 'two')) > } > catch * { > 'Caught error in main module' > }, > local:side-effect('after') > > Regards, > -- Using Opera's revolutionary email client: http://www.opera.com/mail/ _______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
