Files
classroomio/apps/dashboard/src/lib/utils/functions/trycatch.ts
T
Adeyemi AdetunjiandRotimi Best 947181a3c5 feat: custom org brand color (#474)
* feat: add package

* feat: add a new color picker

* feat: integrate with supabase

* feat: add translation

* run translation script

* feat: hover state

* quick fix

* fix: requested PR fixes

* update lock

* ux improvements

* remove log

* cleanup and improve code

---------

Co-authored-by: Rotimi Best <best@classroomio.com>
2024-10-06 01:20:32 +01:00

15 lines
296 B
TypeScript

export function tc<T>(tryFunc: () => T, catchFunc: T | ((e?: Error) => T)) {
let val: T;
try {
val = tryFunc();
} catch (e: unknown) {
if (typeof catchFunc === 'function') {
// @ts-ignore
val = catchFunc(e);
} else {
val = catchFunc;
}
}
return val;
}