JM Santos
Apr 24, 2021

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 ❤️

JM Santos
JM Santos

No responses yet