TryCatch class

A utility class that provides helper methods for performing error handling and exception handling in synchronous and asynchronous operations.

Use the async method to wrap a Future operation and handle errors and exceptions that may occur during the operation's execution. You can set callbacks to handle different types of outcomes, such as onSuccess for successful operations, onError for unhandled exceptions, onTimeout for operations that exceed a given timeout, and others.

Use the sync method to wrap a synchronous operation and handle errors and exceptions that may occur during its execution. You can set callbacks to handle different types of outcomes, such as onSuccess for successful operations, onError for unhandled exceptions, and others.

Constructors

TryCatch()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

async<T>({required Future<T> future, OnTimeout? onTimeout, OnError? onError, OnWaiting? onWaiting, OnNull? onNull, OnEmpty? onEmpty, void onSuccess(T data)?, Duration timeout = const Duration(milliseconds: 10000)}) Future<void>
Wraps a Future operation and handles errors and exceptions that may occur during its execution.
sync<T>({required T operation(), OnError? onError, OnNull? onNull, OnEmpty? onEmpty, void onSuccess(T data)?}) → void
Synchronously executes an operation and handles various types of responses and errors.