I want to change my current return statement in my XQuery, which is :
return
<p>XML File Stored Successfully</p>
I want to make this return statement capable of handling the situation if there is an error, then return an error code to the user, if there is no error, then return the message above to the user.
I think an if-else construct should be placed under return for my purpose. But I really have no idea what condition should be there for the if, could experts help a little? Thanks in advance.
The XQuery 3.0 working draft introduces try-catch expressions, which might be what you are looking for:
declare namespace err = "http://www.w3.org/2005/xqt-errors";
let $x := "string"
return
try {
$x cast as xs:integer
} catch * {
$err:code (: this variable contains the error code :)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With