Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> In .NET and Java it costs at least 100x as much time to throw an exceptions as to return an error code.

The conjecture is that if checks are always executed while exceptions are free when not thrown.

That said, predicted branches are also fairly free so arguing about this in the abstract is pointless.



In the margin, branches are more likely close to the hot path, so they are more likely to 'pollute' the instruction cache. Whilst exceptions have less of this.

Though profile guided optimization will probably catch this. And it might be that even without, compilers still optimize around this.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: