Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for try/catch/finally in XmlActions #440

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions framework/template/XmlActions.groovy.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,19 @@ ${.node}

</#macro>

<#macro try> try {
<#recurse .node/>
}<#if .node["catch"]?has_content><#list .node["catch"] as catch> catch (<#if catch.@class?has_content>${catch.@class}<#else>Throwable</#if><#if catch.@field?has_content> ${catch.@field}<#else> e</#if>) {
<#recurse catch/>
}</#list>
<#if .node["finally"]?has_content> finally {
<#recurse .node["finally"][0]/>
}</#if></#if>
</#macro>

<#macro catch><#-- do nothing when visiting, only used explicitly inline --></#macro>
<#macro finally><#-- do nothing when visiting, only used explicitly inline --></#macro>

<#-- =================== if/when sub-elements =================== -->

<#macro condition><#-- do nothing when visiting, only used explicitly inline --></#macro>
Expand Down
26 changes: 26 additions & 0 deletions framework/xsd/xml-actions-2.1.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,32 @@ along with this software (see the LICENSE.md file). If not, see
</xs:complexType>
</xs:element>

<xs:element name="try" substitutionGroup="ControlOperations">
<xs:annotation><xs:documentation>
The try element can be used to catch errors
</xs:documentation></xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:group minOccurs="0" maxOccurs="unbounded" ref="AllOperations"/>
<xs:element maxOccurs="unbounded" ref="catch"/>
<xs:element minOccurs="0" ref="finally"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="finally">
<xs:annotation><xs:documentation>The finally block is executed after the catch block</xs:documentation></xs:annotation>
<xs:complexType>
<xs:group minOccurs="0" maxOccurs="unbounded" ref="AllOperations"/>
</xs:complexType>
</xs:element>
<xs:element name="catch">
<xs:annotation><xs:documentation>Catches an exception</xs:documentation></xs:annotation>
<xs:complexType>
<xs:group minOccurs="0" maxOccurs="unbounded" ref="AllOperations"/>
<xs:attribute name="class" type="xs:string"/>
<xs:attribute name="field" type="xs:string"/>
</xs:complexType>
</xs:element>

<xs:group name="IfConditions">
<xs:choice>
Expand Down