Catch exceptions in targets called by foreach

  • Dave Burford

    Dave Burford - 2004-02-19

    I want to do something like ...

        <foreach list="${alist}" param="myParam" target="subTarget" inheritall="true"/>

        <fail if="[any of the subTargets are 'bad']"/>

    i.e. I always want to run all of the sub targets.
    A subtarget knows if it is 'bad' and needs to tell this parent target.
    I can't just set a property in the subtarget, because it is not visible in the parent context.
    I can't use trycatch, because then it will break out of the foreach.

    Any ideas? Have I missed a trick?


    • John Hopkins

      John Hopkins - 2004-02-24

      A way around the problem you are having is to list all the sub targets in the "depends" attribute of a target, like this:

      <target name="doit" depends="a,b,c">
        <echo message="result: ${result}"/>

      Set the 'result' property in a,b or c if something fails.  The 'doit' target will pick it up because they are listed in the 'depends' clause.


Log in to post a comment.