Skip to content

io microsphere lang function ThrowableBiConsumer

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

ThrowableBiConsumer

Type: Interface | Module: microsphere-java-core | Package: io.microsphere.lang.function | Since: 1.0.0

Source: microsphere-java-core/src/main/java/io/microsphere/lang/function/ThrowableBiConsumer.java

Overview

Represents an operation that accepts two input arguments and returns no result, potentially throwing a Throwable. This is the two-arity specialization of ThrowableConsumer.

Additionally, this interface provides a default method (#andThen) to support chaining operations, similar to functional constructs in the JDK.

Example Usage

`ThrowableBiConsumer addAndPrint = (a, b) -> {
    int sum = a + b;
    System.out.println("Sum: " + sum);
`;

addAndPrint.accept(3, 5); // Output: Sum: 8
}

Error Handling Example

`ThrowableBiConsumer parseAndPrint = (str, radix) -> {
    int value = Integer.parseInt(str, radix);
    System.out.println("Parsed value: " + value);
`;

try {
    parseAndPrint.accept("123", 10); // Output: Parsed value: 123
    parseAndPrint.accept("abc", 16); // May throw NumberFormatException
} catch (Throwable t) {
    System.err.println("Error occurred: " + t.getMessage());
}
}

Declaration

public interface ThrowableBiConsumer<T, U>

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

Example 1

ThrowableBiConsumer<Integer, Integer> addAndPrint = (a, b) -> {
    int sum = a + b;
    System.out.println("Sum: " + sum);
};

addAndPrint.accept(3, 5); // Output: Sum: 8

Example 2

ThrowableBiConsumer<String, Integer> parseAndPrint = (str, radix) -> {
    int value = Integer.parseInt(str, radix);
    System.out.println("Parsed value: " + value);
};

try {
    parseAndPrint.accept("123", 10); // Output: Parsed value: 123
    parseAndPrint.accept("abc", 16); // May throw NumberFormatException
} catch (Throwable t) {
    System.err.println("Error occurred: " + t.getMessage());
}

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.lang.function.ThrowableBiConsumer;

See Also

  • BiConsumer
  • Throwable

This documentation was auto-generated from the source code of microsphere-java.

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally