3 ms·
I wonder what the performance difference is when you're actually handling the errors though. I'd imagine that try { doThing(); } catch (Exceptio
by maxpolun 10y ago
I wonder what the performance difference is when you're actually handling the errors though. I'd imagine that
try {
doThing();
} catch (Exception1 e) {
handleError1();
} catch (Exception2 e) {
handleError2();
} catch (Exception3 e) {
handleError3();
}
Might be slower than
Error err = doThing();
if (err.code === ERROR1) {
handleError1();
} else if (err.code === ERROR2) {
handleError2();
} else if (err.code === ERROR3) {
handleError3();
}
Exceptions are best in my mind when they are very coarsely-grained, and error-codes best when you need to handle very fine-grained errors. This is certainly true in the code ergonomics, but I'd be interested in seeing if it's true for performance as well.