Skip to content

io microsphere lang function ThrowableFunction

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

ThrowableFunction

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/ThrowableFunction.java

Overview

Represents a function that accepts one argument and produces a result, which may throw a checked exception.

This interface is similar to Function, but allows the functional method to throw any Throwable. It also provides default methods for composing functions and handling exceptions gracefully.

Example Usage

`// ### Example Usage
ThrowableFunction parser = Integer::valueOf;

// Using execute() with default exception handling (throws RuntimeException)
Integer result1 = parser.execute("123"); // returns 123

// Using execute() with custom exception handling
Integer result2 = parser.execute("invalid", (input, ex) -> {
    System.out.println("Parsing failed for: " + input);
    return -1; // fallback value
`);
}

Declaration

public interface ThrowableFunction<T, R>

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

// <h3>Example Usage</h3>
ThrowableFunction<String, Integer> parser = Integer::valueOf;

// Using execute() with default exception handling (throws RuntimeException)
Integer result1 = parser.execute("123"); // returns 123

// Using execute() with custom exception handling
Integer result2 = parser.execute("invalid", (input, ex) -> {
    System.out.println("Parsing failed for: " + input);
    return -1; // fallback value
});

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.ThrowableFunction;

See Also

  • Function
  • 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