export namespace dfunction { type FuncWithFallback = { (defaultValue: T): T; }; /************************* Function will encapsulte exception ---- * * // Example usage function divide(a: number, b: number): number { if (b === 0) { throw new Error("Division by zero"); } return a / b; } const safeDivide = withTryCatch(() => divide(10, 0), -1); const result = safeDivide(42); */ export function withTryCatch(func: () => T, defaultValue: T): FuncWithFallback { return (fallbackValue: T) => { try { return func(); } catch (error) { console.error("An error occurred:", error); return fallbackValue; } }; } }