<p:try name? = NCName> (p:variable*, p:group, p:catch) </p:try>
Within a <p:try> step, possible dynamic errors are caught before an abort. The desired subpipeline is combined within a <p:group> step and executed. If an error occurs, it is caught by a so-called <p:catch> step.
<p:catch name? = NCName> ((p:output | p:log)*, subpipeline) </p:catch>
Instead of an abort, the subpipeline is executed within the <p:catch> step. Depending on the situation, this can be an appropriately formulated error output or an alternative path with further steps.
In the following example an error is deliberately produced and will thus get into the subpipeline of <p:catch>.
<?xml version="1.0" encoding="UTF-8"?> <p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0"> <p:input port="source"> <p:document href="FilmCollection.xml"/> </p:input> <p:output port="result"/> <p:try> <p:group> <p:validate-with-xml-schema assert-valid="true" mode="strict"> <p:input port="schema"> <p:document href="example_5_xmlschema.xsd"/> </p:input> </p:validate-with-xml-schema> </p:group> <p:catch> <p:identity> <p:input port="source"> <p:inline> <c:result>Unfortunately, the document is not valid.</c:result> </p:inline> </p:input> </p:identity> </p:catch> </p:try> </p:declare-step>
The subpipeline in the <p:group> element corresponds to the one in the previous example of <p:validate-with-xml-schema>. If the step produces an error, which means that the original document is not valid against the underlying Schema file, the <p:catch> step is called up and its subpipeline is outputted. In this example, it is a <p:inline> output with an explanatory text. If the document is not valid, the following output is generated:
<c:result xmlns:c="http://www.w3.org/ns/xproc-step">Unfortunately, the document is not valid.</c:result>