ExceptionCatch (Java SE 26 & JDK 26)
Description: declaration: module: java.base, package: java.lang.classfile.instruction, interface: ExceptionCatch
Keywords: java.lang.classfile.instruction.ExceptionCatch interface

# Interface ExceptionCatch

All Superinterfaces:
  `ClassFileElement, CodeElement, PseudoInstruction`

public sealed interface ExceptionCatch extends PseudoInstruction
A pseudo-instruction modeling an entry in the `exception_table` array of a `Code` attribute. Catch (JVMS 3.12) and finally (JVMS 3.14) blocks in Java source code compile to exception table entries. The order of exception table entries is significant: when an exception is thrown in a method, execution branches to the first matching exception handler if such a handler exists (JVMS 2.10). Delivered as a `CodeElement` when traversing the contents of a `CodeModel`.

An exception table entry is composite:

    ExceptionCatch(
        Label handler,
        Label tryStart,
        Label tryEnd,
        Optional<ClassEntry> catchType
    )

See Java Virtual Machine Specification:
  4.7.3 The `Code` Attribute
Since:
  24
See Also:
  - `CodeBuilder::exceptionCatch`
  - `CodeModel.exceptionHandlers()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Optional<ClassEntry>`
  `catchType()`
  Returns the type of the exception to catch, or empty if this handler catches everything.
  `Label`
  `handler()`
  Returns the handler for the exception.
  `static ExceptionCatch`
  `of(Label handler, Label tryStart, Label tryEnd)`
  Returns an exception table pseudo-instruction to catch everything.
  `static ExceptionCatch`
  `of(Label handler, Label tryStart, Label tryEnd, Optional<ClassEntry> catchTypeEntry)`
  Returns an exception table pseudo-instruction.
  `Label`
  `tryEnd()`
  Returns the end of the instruction range for the guarded instructions.
  `Label`
  `tryStart()`
  Returns the beginning of the instruction range for the guarded instructions.

- ## Method Details

  - ### handler

    Label handler()
    Returns the handler for the exception.
    Returns:
      the handler for the exception

  - ### tryStart

    Label tryStart()
    Returns the beginning of the instruction range for the guarded instructions.
    Returns:
      the beginning of the instruction range for the guarded instructions

  - ### tryEnd

    Label tryEnd()
    Returns the end of the instruction range for the guarded instructions.
    Returns:
      the end of the instruction range for the guarded instructions

  - ### catchType

    Optional<ClassEntry> catchType()
    Returns the type of the exception to catch, or empty if this handler catches everything.
    Returns:
      the type of the exception to catch, or empty if this handler catches everything

  - ### of

    static ExceptionCatch of(Label handler, Label tryStart, Label tryEnd, Optional<ClassEntry> catchTypeEntry)
    Returns an exception table pseudo-instruction.
    Parameters:
      `handler` - the handler for the exception
      `tryStart` - the beginning of the instruction range for the guarded instructions
      `tryEnd` - the end of the instruction range for the guarded instructions
      `catchTypeEntry` - the type of exception to catch, or empty if this handler is unconditional
    Returns:
      an exception table pseudo-instruction

  - ### of

    static ExceptionCatch of(Label handler, Label tryStart, Label tryEnd)
    Returns an exception table pseudo-instruction to catch everything.
    Parameters:
      `handler` - the handler for the exception
      `tryStart` - the beginning of the instruction range for the guarded instructions
      `tryEnd` - the end of the instruction range for the guarded instructions
    Returns:
      an exception table pseudo-instruction to catch everything