try {
// ...
} catch (IOException e) {
// ...
} finally {
// ...
}
In this code, "// do things" is the content of the tryBlock, there is one catch clause that catches IOException e,
and there is a finally block.
The catch and finally blocks are optional, but they should not be empty at the same time.
try (InputStream i = new FileInputStream("file")) {
// ...
} catch (IOException|NullPointerException e) {
// ...
} finally {
// ...
}
Java 7 introduced two things:
try (r) {
// ...
} catch (IOException|NullPointerException e) {
// ...
} finally {
// ...
}
Java 9 finishes resources: you can now refer to a resource that was declared somewhere else.
The following types are allowed:
CatchClause, com.github.javaparser.ast.type.IntersectionType , com.github.javaparser.ast.expr.FieldAccessExpr , com.github.javaparser.ast.expr.NameExpr
| Modifier and Type | Field and Description |
|---|---|
| private NodeList | |
| private BlockStmt | |
| private NodeList | |
| private BlockStmt |
| Access | Constructor and Description |
|---|---|
| public | |
| public | TryStmt(final BlockStmt tryBlock, final NodeList<CatchClause> catchClauses, final BlockStmt finallyBlock)
|
| public | TryStmt(NodeList<Expression> resources, final BlockStmt tryBlock, final NodeList<CatchClause> catchClauses, final BlockStmt finallyBlock)
|
| public | TryStmt(TokenRange tokenRange, NodeList<Expression> resources, BlockStmt tryBlock, NodeList<CatchClause> catchClauses, BlockStmt finallyBlock)
This constructor is used by the parser and is considered private. |
| Modifier and Type | Method and Description |
|---|---|
| public <R, A> R | accept(final GenericVisitor<R, A>
the visitor implementation v, final A the argument passed to the visitor (of type A) arg)Implements com. |
| public <A> void | accept(final VoidVisitor<A>
the visitor implementation v, final A any value relevant for the visitor (of type A) arg)Implements com. |
| public TryStmt | |
| public TryStmt | clone()
Creates and returns a copy of this object.
|
| public NodeList | |
| public Optional | |
| public TryStmtMetaModel | |
| public NodeList | |
| public BlockStmt | |
| public void | |
| public boolean | |
| public boolean | |
| public TryStmt | |
| public TryStmt | |
| public boolean | |
| public TryStmt | |
| public TryStmt | |
| public TryStmt | |
| public TryStmt | |
| public Optional |
| catchClauses | back to summary |
|---|---|
| private NodeList<CatchClause> catchClauses | |
| finallyBlock | back to summary |
|---|---|
| private BlockStmt finallyBlock
| |
| resources | back to summary |
|---|---|
| private NodeList<Expression> resources | |
| tryBlock | back to summary |
|---|---|
| private BlockStmt tryBlock | |
| TryStmt | back to summary |
|---|---|
| public TryStmt() | |
| TryStmt | back to summary |
|---|---|
| public TryStmt(final BlockStmt tryBlock, final NodeList<CatchClause> catchClauses, final BlockStmt finallyBlock) | |
| TryStmt | back to summary |
|---|---|
public TryStmt(NodeList<Expression> resources, final BlockStmt tryBlock, final NodeList<CatchClause> catchClauses, final BlockStmt finallyBlock)
| |
| TryStmt | back to summary |
|---|---|
| public TryStmt(TokenRange tokenRange, NodeList<Expression> resources, BlockStmt tryBlock, NodeList<CatchClause> catchClauses, BlockStmt finallyBlock) This constructor is used by the parser and is considered private.
| |
| accept | back to summary |
|---|---|
| public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) Implements com. Doc from com. Accept method for visitor support.
| |
| accept | back to summary |
|---|---|
| public <A> void accept(final VoidVisitor<A> v, final A arg) Implements com. Doc from com. Accept method for visitor support.
| |
| asTryStmt | back to summary |
|---|---|
| public TryStmt asTryStmt() Overrides com.
| |
| clone | back to summary |
|---|---|
| public TryStmt clone() Overrides com. Doc from java. Creates and returns a copy of this object. The precise meaning
of "copy" may depend on the class of the object. The general
intent is that, for any object will be true, and that the expression:x.clone() != x will bex.clone().getClass() == x.getClass() true, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x) true, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by
| |
| getCatchClauses | back to summary |
|---|---|
public NodeList
| |
| getFinallyBlock | back to summary |
|---|---|
public Optional
| |
| getMetaModel | back to summary |
|---|---|
| public TryStmtMetaModel getMetaModel() Overrides com.
| |
| getResources | back to summary |
|---|---|
public NodeList
| |
| getTryBlock | back to summary |
|---|---|
public BlockStmt getTryBlock()
| |
| ifTryStmt | back to summary |
|---|---|
| public void ifTryStmt(Consumer<TryStmt> action) Overrides com.
| |
| isTryStmt | back to summary |
|---|---|
| public boolean isTryStmt() Overrides com.
| |
| remove | back to summary |
|---|---|
| public boolean remove(Node node) Overrides com.
| |
| removeFinallyBlock | back to summary |
|---|---|
public TryStmt removeFinallyBlock()
| |
| removeTryBlock | back to summary |
|---|---|
public TryStmt removeTryBlock()
| |
| replace | back to summary |
|---|---|
| public boolean replace(Node node, Node replacementNode) Overrides com.
| |
| setCatchClauses | back to summary |
|---|---|
public TryStmt setCatchClauses(final NodeList<CatchClause> catchClauses)
| |
| setFinallyBlock | back to summary |
|---|---|
public TryStmt setFinallyBlock(final BlockStmt finallyBlock)
| |
| setResources | back to summary |
|---|---|
public TryStmt setResources(final NodeList<Expression> resources)
| |
| setTryBlock | back to summary |
|---|---|
public TryStmt setTryBlock(final BlockStmt tryBlock)
| |
| toTryStmt | back to summary |
|---|---|
| public Optional Overrides com.
| |