Skip to content

Exceptions table management

hydrophobis edited this page Mar 25, 2025 · 2 revisions

Overview

These functions manage the exceptions table section of the Java class file. The exceptions table describes the exception handlers for different sections of the bytecode.


1. Exception Table Management

  • void exceptions_start()
    Initializes the exceptions table. Reserves space for the exception_table_length and starts the counter for entries.

  • void exception_entry(uint16_t start_pc, uint16_t end_pc, uint16_t handler_pc, uint16_t catch_type)
    Adds an entry to the exception table for a specific range of bytecode instructions and their associated exception handler.

  • void exceptions_end()
    Finalizes the exceptions table by patching the exception_table_length at the reserved location.


2. Utility Functions

  • void patch_u2(size_t pos, uint16_t v)
    Updates a 2-byte value in the buffer (used to finalize exception_table_length).

  • size_t current_offset()
    Returns the current offset in the bytecode buffer.


Usage Example

exceptions_start();
exception_entry(0, 10, 20, 1); // Defines an exception handler for a specific bytecode range
exception_entry(30, 50, 60, 2); // Another exception handler
exceptions_end();

This will generate an exceptions table with two entries.


Clone this wiki locally