3 ms·
For JS devs, I’ve found it’s actually best to isolate your exception handling from exceptional logic. As in, this will perform worse called in a hot loop: fu
by eyelidlessness 4y ago
For JS devs, I’ve found it’s actually best to isolate your exception handling from exceptional logic. As in, this will perform worse called in a hot loop:
function fallible(a) {
try {
return anything(a)
} catch {
const b = somethingElse(a)
return anotherThing(b)
}
}
… than if your somethingElse case handles anotherThing, or if you do more work in the try block. In some cases exception throwing outperforms if conditions as long as both the try and catch blocks only do one thing each.