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,

-- 
Florent Georges
H2O Consulting
http://h2o.consulting/
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to