Function to throw an exception
Tuesday, 9 June 2015 · 3 messages
C
cmarchand9 Jun 2015 10:53 #
Hello,
Before doing some updates, I want to check many things. If those checks fail, I want to throw an error, to allow the calling program be notified of the error.
I do not want to avoid the updates, but really want to throw an error.
Is there such a function ?
Christophe
CG
Christian Grün9 Jun 2015 10:58 #
Hi Christophe,
Quoted text · cmarchand · 1 line
> I do not want to avoid the updates, but really want to throw an error.
I'm not sure how to interpret your statement.. Do you want to execute the updates AND throw an error?
If you throw an error, your updates won't be executed, so this may already be what you need. See the following example..
let $data := <my-data/>
return if($data/*) then (
insert node $data into db:open('db')/xml
) else (
error((), 'Root has no child elements!')
)Best,
Christian
C
cmarchand9 Jun 2015 11:08 #
That's exactly what I want !
Thanks a lot !
Christophe
Quoted text · Christian Grün · 20 lines
Le 2015-06-09 10:58, Christian Grün a écrit : > Hi Christophe, > >> I do not want to avoid the updates, but really want to throw an error. > > I'm not sure how to interpret your statement.. Do you want to execute > the updates AND throw an error? > > If you throw an error, your updates won't be executed, so this may > already be what you need. See the following example.. > > let $data := <my-data/> > return if($data/*) then ( > insert node $data into db:open('db')/xml > ) else ( > error((), 'Root has no child elements!') > ) > > Best, > Christian
Written for BaseX 8.2. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery