This repository has been archived on 2026-03-28. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files

20 lines
510 B
TypeScript

export async function asynctryexpr<T>(cb: () => Promise<T>): Promise<[ Error, null ] | [ null, T ]> {
try {
const val = await cb();
return [ null, val ];
} catch(e) {
if(e instanceof Error) return [ e, null ];
return [ new Error(`${e}`), null ];
}
}
export function tryexpr<T>(cb: () => T): [ Error, null ] | [ null, T ] {
try {
const val = cb();
return [ null, val ];
} catch(e) {
if(e instanceof Error) return [ e, null ];
return [ new Error(`${e}`), null ];
}
}