Skip to content

Instantly share code, notes, and snippets.

@jswhisperer
Last active November 11, 2023 14:16
Show Gist options
  • Save jswhisperer/8d8b319fe8b1b8f17c16f286b57ef60f to your computer and use it in GitHub Desktop.
Save jswhisperer/8d8b319fe8b1b8f17c16f286b57ef60f to your computer and use it in GitHub Desktop.
tryCatch.ts
type TryCatchProps<T> = {
tryFn: () => T;
catchFn: (error: unknown) => T;
}
function tryCatch<T>({ tryFn, catchFn }: TryCatchProps<T>): T {
try {
return tryFn();
} catch (error) {
return catchFn(error);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment