Interface CodeBuilder.CatchBuilder
- Enclosing interface:
CodeBuilder
The order of catch blocks is significant. When an exception is thrown by the try block, the first catch block whose exception type is the same class as or a superclass of the class of exception thrown is branched to (JVMS 2.10).
- Since:
- 24
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncatching(ClassDesc exceptionType, Consumer<CodeBuilder.BlockCodeBuilder> catchHandler) Adds a catch block that catches an exception of the given type.voidcatchingAll(Consumer<CodeBuilder.BlockCodeBuilder> catchAllHandler) Adds a "catch" block that catches all exceptions.catchingMulti(List<ClassDesc> exceptionTypes, Consumer<CodeBuilder.BlockCodeBuilder> catchHandler) Adds a catch block that catches exceptions of the given types.
-
Method Details
-
catching
CodeBuilder.CatchBuilder catching(ClassDesc exceptionType, Consumer<CodeBuilder.BlockCodeBuilder> catchHandler) Adds a catch block that catches an exception of the given type.The caught exception will be on top of the operand stack when the catch block is entered.
The
CodeBuilder.BlockCodeBuilder.breakLabel()for the catch block corresponds to the break label of thetryHandlerblock inCodeBuilder.trying(Consumer, Consumer).If the type of exception is
nullthen the catch block catches all exceptions.- API Note:
- If the type of exception to catch is already handled by previous catch blocks, this block will never be executed.
- Parameters:
exceptionType- the type of exception to catch, may benullcatchHandler- handler that receives aCodeBuilder.BlockCodeBuilderto generate the body of the catch block- Returns:
- this builder
- Throws:
IllegalArgumentException- ifexceptionTyperepresents a primitive type- See Also:
-
catchingMulti
CodeBuilder.CatchBuilder catchingMulti(List<ClassDesc> exceptionTypes, Consumer<CodeBuilder.BlockCodeBuilder> catchHandler) Adds a catch block that catches exceptions of the given types.The caught exception will be on top of the operand stack when the catch block is entered.
The
CodeBuilder.BlockCodeBuilder.breakLabel()for the catch block corresponds to the break label of thetryHandlerblock inCodeBuilder.trying(Consumer, Consumer).If list of exception types is empty then the catch block catches all exceptions.
- API Note:
- If every type of exception to catch is already handled by previous catch blocks, this block will never be executed.
- Parameters:
exceptionTypes- the types of exception to catchcatchHandler- handler that receives aCodeBuilder.BlockCodeBuilderto generate the body of the catch block- Returns:
- this builder
- Throws:
IllegalArgumentException- if any exception type represents a primitive type- See Also:
-
catchingAll
Adds a "catch" block that catches all exceptions.The
CodeBuilder.BlockCodeBuilder.breakLabel()for the catch block corresponds to the break label of thetryHandlerblock inCodeBuilder.trying(Consumer, Consumer).The caught exception will be on top of the operand stack when the catch block is entered.
- API Note:
- Since this block intercepts all exceptions, all subsequent catch blocks will never be executed.
- Parameters:
catchAllHandler- handler that receives aCodeBuilder.BlockCodeBuilderto generate the body of the catch block- See Also:
-