prepareExceptionFunction method
- {ExceptionExplanationModel? exceptionExplanationModel,
- BuildContext? context}
Prepares a general Exception handling function based on the provided context and exception model.
exceptionExplanationModel
contains information about the exception for displaying in the alert dialog.context
is the current build context.generalFunction
is a function to handle exceptions when a specific function is not provided, andcontext
is null. It is only invoked in this case.
Returns a function to handle the general Exception.
Implementation
bool Function(Exception exception)? prepareExceptionFunction({
ExceptionExplanationModel? exceptionExplanationModel,
BuildContext? context,
}) {
if (context == null) {
return (Exception exception) {
debugPrint(exception.toString());
return true;
};
}
return (Exception exception) => showAlertDialog(
context,
exceptionExplanationModel?.title ?? "Unknown Error",
exceptionExplanationModel?.content ?? "An unexpected error occurred.",
exceptionExplanationModel?.buttonContent ?? "Close",
);
}