Yes, you can apply this approach to both sync and async functions.
Actually, I have both `tryCatchSync` and `tryCatch`, and here’s the example
export const tryCatch = async (
tryer,
) => {
try {
const result = await tryer();
return [result, null];
} catch (error) {
return [null, error];
}
};export const tryCatchSync = (
tryer,
) => {
try {
const result = tryer();
return [result, null];
} catch (error) {
return [null, error];
}
};
Thanks for reading ❤️