|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
it.haefelinger.flaka.TryCatch
public class TryCatch
A wrapper that lets you run a set of tasks and optionally run a different set of tasks if the first set fails and yet another set after the first one has finished.
This mirrors Java's try/catch/finally.
The tasks inside of the required <try> element will be
run. If one of them should throw a
BuildException several things can
happen:
<catch> block, the exception will be
passed through to Ant.<catch> block, the tasks nested into it
will be run.
If a <finally> block is present, the task nested into it
will be run, no matter whether the first tasks have thrown an exception or
not.
Attributes:
| Name | Description | Required |
| property | Name of a property that will receive the message of the exception that has been caught (if any) | No |
| reference | Id of a reference that will point to the exception object that has been caught (if any) | No |
Use the following task to define the <trycatch> task
before you use it the first time:
<code>
<taskdef name="trycatch"
classname="net.sf.antcontrib.logic.TryCatchTask" />
</code>
<code>
<trycatch property="foo" reference="bar">
<try>
<fail>Tada!</fail>
</try>
<catch>
<echo>In <catch>.</echo>
</catch>
<finally>
<echo>In <finally>.</echo>
</finally>
</trycatch>
<echo>As property: ${foo}</echo>
<property name="baz" refid="bar" />
<echo>From reference: ${baz}</echo>
</code>
results in
<code>
[trycatch] Caught exception: Tada!
[echo] In <catch>.
[echo] In <finally>.
[echo] As property: Tada!
[echo] From reference: Tada!
</code>
| Nested Class Summary | |
|---|---|
static class |
TryCatch.CatchBlock
A helper class implementing a catch clause. |
| Field Summary | |
|---|---|
protected List |
catchlist
|
protected List |
finallylist
|
protected String |
property
|
protected String |
reference
|
static String |
REFERENCE
|
protected List |
trylist
|
| Fields inherited from class org.apache.tools.ant.Task |
|---|
target, taskName, taskType, wrapper |
| Fields inherited from class org.apache.tools.ant.ProjectComponent |
|---|
description, location, project |
| Constructor Summary | |
|---|---|
TryCatch()
|
|
| Method Summary | |
|---|---|
void |
addCatch(TryCatch.CatchBlock cb)
Add a catch clause. |
void |
addFinally(Sequential seq)
Adds a finally clause. |
void |
addTry(Sequential seq)
A a sequential task container to the list of tries. |
void |
execute()
|
static void |
main(String[] args)
|
protected void |
saveit(Throwable e)
|
void |
setProperty(String p)
Sets the property attribute. |
void |
setReference(String r)
Sets the reference attribute. |
| Methods inherited from class org.apache.tools.ant.Task |
|---|
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType |
| Methods inherited from class org.apache.tools.ant.ProjectComponent |
|---|
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String REFERENCE
protected List trylist
protected List catchlist
protected List finallylist
protected String property
protected String reference
| Constructor Detail |
|---|
public TryCatch()
| Method Detail |
|---|
public void addTry(Sequential seq)
seq - public void addCatch(TryCatch.CatchBlock cb)
cb - public void addFinally(Sequential seq)
seq - public void setProperty(String p)
public void setReference(String r)
protected void saveit(Throwable e)
public void execute()
throws BuildException
execute in class TaskBuildExceptionpublic static void main(String[] args)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||