Class ErrorClassifier
java.lang.Object
express.mvp.myra.transport.error.ErrorClassifier
Classifies exceptions into error categories for recovery decisions.
This classifier uses a combination of exception type matching and message analysis to categorize errors appropriately. Custom classifiers can be registered for application-specific exceptions.
Classification Strategy
- Check custom classifiers first (exact type match)
- Check for JVM errors (VirtualMachineError, etc.)
- Check exception type hierarchy
- Analyze exception message for patterns
- Default to UNKNOWN if unclassifiable
Usage Example
try {
transport.send(data);
} catch (Exception e) {
ErrorCategory category = ErrorClassifier.classify(e);
if (category.isRetryable()) {
retryPolicy.handleRetryable(e, category);
} else {
handleFatalError(e);
}
}
Custom Classifiers
// Register custom exception type
ErrorClassifier.registerClassifier(
MyAppException.class,
e -> e.isRetryable() ? ErrorCategory.TRANSIENT : ErrorCategory.FATAL
);
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic ErrorCategoryClassifies an exception into an error category.static voidClears all custom classifiers.static StringdescribeError(Throwable throwable) Returns a detailed description of the classification result.static <T extends Throwable>
voidregisterClassifier(Class<T> exceptionType, Predicate<Throwable> classifier) Registers a custom classifier for a specific exception type.static voidremoveClassifier(Class<? extends Throwable> exceptionType) Removes a previously registered custom classifier.
-
Method Details
-
classify
Classifies an exception into an error category.- Parameters:
throwable- the exception to classify- Returns:
- the error category
-
registerClassifier
public static <T extends Throwable> void registerClassifier(Class<T> exceptionType, Predicate<Throwable> classifier) Registers a custom classifier for a specific exception type.Custom classifiers are checked before built-in classification. The predicate receives the exception and should return true if it matches the custom category.
- Type Parameters:
T- the exception type- Parameters:
exceptionType- the exception class to matchclassifier- predicate that returns true if exception matches expected category
-
removeClassifier
-
clearCustomClassifiers
public static void clearCustomClassifiers()Clears all custom classifiers. -
describeError
-