Implementation:Apache Flink FatalExceptionClassifier IsFatal
| Knowledge Sources | |
|---|---|
| Domains | Stream_Processing, Error_Handling |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
Concrete tool for classifying exceptions as fatal or retryable in async sink operations provided by the Apache Flink connector-base module.
Description
The FatalExceptionClassifier uses a Predicate<Throwable> to match exceptions and a Function<Throwable, Exception> to map them. The isFatal method walks the exception chain to find the root cause and tests it against the predicate. Multiple classifiers can be chained via createChain. The static factory withRootCauseOfType creates a classifier matching a specific exception class.
Usage
Create classifiers for your custom async sink to define which destination-specific exceptions should fail the job vs. be retried.
Code Reference
Source Location
- Repository: Apache Flink
- File: flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/sink/throwable/FatalExceptionClassifier.java
- Lines: L32-86
Signature
@Internal
public class FatalExceptionClassifier {
public FatalExceptionClassifier(
Predicate<Throwable> validator,
Function<Throwable, Exception> throwableMapper);
public boolean isFatal(Throwable err, Consumer<Exception> throwableConsumer);
public static FatalExceptionClassifier withRootCauseOfType(
Class<? extends Throwable> type,
Function<Throwable, Exception> mapper);
public static FatalExceptionClassifier createChain(
FatalExceptionClassifier... classifiers);
}
Import
import org.apache.flink.connector.base.sink.throwable.FatalExceptionClassifier;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| err | Throwable | Yes | Exception to classify |
| throwableConsumer | Consumer<Exception> | Yes | Callback for fatal exceptions |
Outputs
| Name | Type | Description |
|---|---|---|
| isFatal | boolean | true if the exception is fatal, false if retryable |
Usage Examples
Creating a Classifier Chain
FatalExceptionClassifier classifier = FatalExceptionClassifier.createChain(
FatalExceptionClassifier.withRootCauseOfType(
AccessDeniedException.class,
err -> new FlinkRuntimeException("Access denied", err)),
FatalExceptionClassifier.withRootCauseOfType(
ResourceNotFoundException.class,
err -> new FlinkRuntimeException("Resource not found", err))
);
// Usage in ResultHandler:
// if (classifier.isFatal(exception, fatalConsumer)) {
// // Job will fail
// } else {
// // Re-buffer failed entries for retry
// }