Skip to content

Commit 5b36b9d

Browse files
committed
Update ThrowableFunction.java
1 parent 599d17f commit 5b36b9d

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

microsphere-java-core/src/main/java/io/microsphere/lang/function/ThrowableFunction.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,30 @@
2222
import static io.microsphere.util.Assert.assertNotNull;
2323

2424
/**
25-
* {@link Function} with {@link Throwable}
25+
* Represents a function that accepts one argument and produces a result, which may throw a checked exception.
26+
* <p>
27+
* This interface is similar to {@link Function}, but allows the functional method to throw any {@link Throwable}.
28+
* It also provides default methods for composing functions and handling exceptions gracefully.
29+
* </p>
2630
*
27-
* @param <T> the source type
28-
* @param <R> the return type
31+
* <h2>Examples</h2>
32+
* <pre>{@code
33+
* // Example usage:
34+
* ThrowableFunction<String, Integer> parser = Integer::valueOf;
35+
*
36+
* // Using execute() with default exception handling (throws RuntimeException)
37+
* Integer result1 = parser.execute("123"); // returns 123
38+
*
39+
* // Using execute() with custom exception handling
40+
* Integer result2 = parser.execute("invalid", (input, ex) -> {
41+
* System.out.println("Parsing failed for: " + input);
42+
* return -1; // fallback value
43+
* });
44+
* }</pre>
45+
*
46+
* @param <T> the type of the input to the function
47+
* @param <R> the type of the result of the function
48+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
2949
* @see Function
3050
* @see Throwable
3151
* @since 1.0.0

0 commit comments

Comments
 (0)