handleGenericException static method
Handles generic exceptions and wraps them in appropriate YOLO exceptions.
e
The generic exception to handle
context
Optional context string for more specific error messages
Returns the appropriate YOLOException
Implementation
static YOLOException handleGenericException(dynamic e, {String? context}) {
final contextPrefix = context != null ? '$context: ' : '';
if (e is YOLOException) {
return e;
}
if (e.toString().contains('MissingPluginException')) {
if (context != null && context.contains('load model')) {
return ModelLoadingException(
'${contextPrefix}Model loading failed: $e',
);
} else if (context != null && context.contains('switch to model')) {
return ModelLoadingException(
'${contextPrefix}Model switching failed: $e',
);
} else if (context != null && context.contains('predict')) {
return InferenceException('${contextPrefix}Inference failed: $e');
}
}
return InferenceException('${contextPrefix}Unknown error: $e');
}