Skip to content

io microsphere lang function ThrowableConsumer

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

ThrowableConsumer

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

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

Overview

Represents an operation that accepts a single input argument and returns no result, which may throw a Throwable.

This is the two-arity specialization of Function and the throwable-aware functional interface whose functional method is #accept(Object).

Example Usage

`// Basic usage:
ThrowableConsumer printer = System.out::println;

printer.accept("Hello World"); // Outputs: Hello World

// Throwing an exception:
ThrowableConsumer riskyConsumer = i -> {
    if (i

### Declaration

```java
public interface ThrowableConsumer
```

**Author:** Mercy

## Version Information

- **Introduced in:** `0.1.10-SNAPSHOT` (current)
- **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

```java
// Basic usage:
ThrowableConsumer printer = System.out::println;

printer.accept("Hello World"); // Outputs: Hello World

// Throwing an exception:
ThrowableConsumer riskyConsumer = i -> {
    if (i < 0) {
        throw new IllegalArgumentException("Negative value not allowed");
    }
};

try {
    riskyConsumer.accept(-1);
} catch (Throwable t) {
    System.err.println("Caught exception: " + t.getMessage());
}
```

## Usage

### Maven Dependency

Add the following dependency to your `pom.xml`:

```xml

    io.github.microsphere-projects
    microsphere-java-core
    ${microsphere-java.version}

```

> **Tip:** Use the BOM (`microsphere-java-dependencies`) for consistent version management. See the [Getting Started](https://github.com/microsphere-projects/microsphere-java#getting-started) guide.

### Import

```java
import io.microsphere.lang.function.ThrowableConsumer;
```

## See Also

- `Consumer`
- `Throwable`

---

*This documentation was auto-generated from the source code of [microsphere-java](https://github.com/microsphere-projects/microsphere-java).*

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally