js
Promise.try(fn, ...args)من غيرها، لو الدالة رمت خطأ قبل ما ترجّع promise، الخطأ بيطلع برّه الـpromise ومش بيتمسك بـcatch. Promise.try بتقفل الفراغ ده.
البرهان
js
const boom = () => { throw new Error('متزامن'); };
try { boom(); } catch (e) { console.log('catch عادي:', e.message); }
Promise.try(boom).catch((e) => console.log('promise مرفوضة:', e.message));
await new Promise((r) => setTimeout(r, 10));النتيجة
catch عادي: متزامن promise مرفوضة: متزامن