export async function asynctryexpr(cb: () => Promise): 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(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 ]; } }