Clarity

 View Only
  • 1.  Finally tag in Gel script

    Posted Mar 27, 2014 07:06 AM

    Is there any tag in Gel script which will always get executed , even though something went wrong in Script as we have in .net and java.

     

    try{

    }

    catch{

    }

    finally

    {

    }

    in above case code written in finally is always executed even if any exception is raised or code execution is completed successfully. I want to do same thing GEL Script

    We use core:catch in Gel, So is there anything for finally ???



  • 2.  Moving to XOG/GEL/WSDL Board

     
    Posted Mar 28, 2014 02:48 PM
    Moving to XOG/GEL/WSDL Board for better visibility.


  • 3.  RE: Finally tag in Gel script
    Best Answer

    Broadcom Employee
    Posted Mar 28, 2014 06:02 PM

    I think the following will do it:

    <!-- start of script with usual headers, etc -->
    <core:catch var="err">
        <!-- do stuff -->
    </core:catch>
    <core:if test="${not empty(err)}">
        <!-- do stuff because an error was trapped -->
    </core:if>
    <!-- finally -->
    <!-- the code will always run to here whether an error was trapped or not -->
        <!-- do end-of-code clean-up stuff  -->
    <!-- end of script -->

     

    Obviously, there's a lot more detail you will have to add.



  • 4.  RE: Finally tag in Gel script

    Posted Mar 28, 2014 08:22 PM

     

    This is how I handle exceptions:

    <?xml version="1.0" encoding="utf-8"?>
    <gel:script xmlns:core="jelly:core"
        xmlns:file="jelly:com.niku.union.gel.FileTagLibrary"
        xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
        xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary"
        xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:sql="jelly:sql" xmlns:xog="http://www.niku.com/xog"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xsl="http://www.w3.org/1999/XML/Transform"
        xmlns:util="jelly:util">
    
        <gel:log message="outerException" />
        <core:catch var="outerException">
            <!-- Setup our script break list for exit if issue -->
            <core:set var="scriptBreak" value="[1]" />
            <core:forEach var="dummy" items="${scriptBreak}">
    
                <!-- Example One  no exception but no need to continue processing -->
                <gel:log message="Test innerOneException" />
                <core:catch var="innerOneException">
                    <core:set var="someVar" value="true" />
    
                    <!-- Toggle to false to test this block     -->
                    <core:set var="codeBlockResults" value="true" />
                </core:catch>
                <core:if test="${innerOneException == null and codeBlockResults != true}">
                    <gel:log message="We didn't get an innerOneException" />
                    <gel:log message="But there isn't a reason to run the rest of the gel script" />
                    <gel:log message="for exampe say our recordset count == 0 -- no need to do any more processing" />
                    <core:break />
                    <!-- This tosses us out fo the dummy forEach loop -->
                </core:if>
    
                <!-- Example Two exception but need finally for this exception -->
                <gel:log message="Test innerTwoException" />
                <core:catch var="innerTwoException">
                    <core:set var="someVar" value="true" />
    
                    <!-- Uncomment to generate exception
                    <core:new var="i" className="java.lang.Integer">
                        <core:arg type="java.lang.String" value="abc" />
                    </core:new>
                    -->
    
                </core:catch>
                <core:if test="${innerTwoException != null}">
                    <gel:log message="We did get an innerTwoException" />
                    <gel:log message="${innerTwoException}" />
    
                    <!--
                             code our catch code block
                    -->
                    
                </core:if>
                <!-- finally block -->
                <gel:log message="Finally code block" />
                <core:if test="${innerTwoException != null}">
                    <core:break />
                </core:if>
    
    
                <!-- Example Three throw outer exception-->
                <gel:log message="Test outerException" />
                <core:set var="someVar" value="true" />
    
                <!-- Uncomment to generate exception
                <core:new var="i" className="java.lang.Integer">
                    <core:arg type="java.lang.String" value="abc" />
                </core:new>
                -->
    
                <!-- Script Break block -->
            </core:forEach>
    
            <!-- Something went wrong let us know -->
        </core:catch>
    
        <core:if test="${outerException != null}">
            <gel:log message="We did get an outer exception" />
            <gel:log level="FATAL" message="${outerException}" />
        </core:if>
    
    </gel:script>

     

    V/r,

    Gene