This is not any conceptual question. just want to correct my logical side.
Case 1:
try {
var to = await new IamErrorAlways()
if (to && to instanceof Error) return to // is this correct way to handle.
} catch (error) {
// report failure.
return error
}
Case 2:
try {
var to = await new IamErrorAlways()
if (!to) throw new error('Expected to to return error') // or is this correct way to handle.
} catch (error) {
// report failure.
return error // <---- catch will return awaited error
}
Out of both which one is good.
await new …never makes sense unless the constructor produces a thenable, and similarly!tocan never be true unlessnew IamErrorAlways()is a thenable.await new, which is the thenable thing that I mentioned. If!('then' in new IamErrorAlways()),var to = await new IamErrorAlways();is exactly equivalent toawait; var to = new IamErrorAlways();, and probably equivalent tovar to = new IamErrorAlways();.