export function tryCatch any>( fn: Fn, onException?: (error: Error) => void, ): ReturnType | undefined { try { const result = fn() return result } catch (error) { onException?.(error as Error) } }