public class TryCatchStatementBuilder
extends java.lang.Object
TryCatchStatement stmt = A.STMT.tryCatchSBuilder()
.tryStmt(protectedStmt)
.addCatchStmt(Exception, 'ex', handlerOneStmt)
.addCatchStmt(IllegalStatementException, 'ix', handlerTwoStmt)
// ... add as many catch as you need
.finallyStmt(finallyStatement)
.build()
Result
try {
// protectedStmt
} catch(Exception ex) {
// handlerOneStmt
} catch(IllegalStateException ix) {
// handlerTwoStmt
} finally {
// finallyStatement
}| Constructor and Description |
|---|
TryCatchStatementBuilder() |
| Modifier and Type | Method and Description |
|---|---|
TryCatchStatementBuilder |
addCatchStmt(ClassNode exceptionType,
java.lang.String exceptionVarName,
Statement stmt)
Adds one catch statement to catch a specific exception giving a
specific name for the exception variable.
|
TryCatchStatementBuilder |
addCatchStmt(java.lang.Class exceptionType,
java.lang.String exceptionVarName,
Statement stmt)
Adds one catch statement to catch a specific exception giving a
specific name for the exception variable.
|
TryCatchStatement |
build()
Returns the created
TryCatchStatement instance. |
TryCatchStatementBuilder |
finallyStmt(Statement stmt)
Adds the statement that will be placed inside the finally block
|
TryCatchStatementBuilder |
tryStmt(Statement stmt)
Adds the try statement
|
public TryCatchStatementBuilder tryStmt(Statement stmt)
stmt - the code you want to protectpublic TryCatchStatementBuilder addCatchStmt(java.lang.Class exceptionType, java.lang.String exceptionVarName, Statement stmt)
Class to specify the class of the Exception. Don't
use it if you are targetting a very early compilation stage. If so use the method
using ClassNodeexceptionType - the Class of the exception you want to catchexceptionVarName - the name of the exception variablestmt - the code handling the exceptionpublic TryCatchStatementBuilder addCatchStmt(ClassNode exceptionType, java.lang.String exceptionVarName, Statement stmt)
exceptionType - the ClassNode of the exception you want to catchexceptionVarName - the name of the exception variablestmt - the code handling the exceptionpublic TryCatchStatementBuilder finallyStmt(Statement stmt)
stmt - the code executed in the finally blockpublic TryCatchStatement build()
TryCatchStatement instance. At
least the "try" statement and the "finally" statement must be
provided. Otherwise it will throw a IllegalStateExceptionTryCatchStatement instancejava.lang.IllegalStateException - if neither try nor finally statements are provided