> you basically end up comparing "correct" to "not correct" code.

not quite: there are two points worth keeping in mind with exceptions: they 
incur a significant cost no matter if you use them or not - ie the mere 
possibility of there being an exception raised leads to significant overhead 
and missed optimization opportunities (because code must be generated 
defensively) - this becomes evident when you start adorning your code with 
`throw()` in C++ or indeed disable them completely - in nim, `raises: []` is 
not enough since we have to deal with defects too that unfortunately use the 
same exception mechanism.

The second point would be that exceptions will always be at least as slow or 
slower due to the dynamic typing overhead (vs non-dynamically-typed solutions, 
based on the assumption that exceptions indeed are heap-allocated and 
dynamically typed like in Nim). If you ignore all the syntactic differences and 
write perfect exception-safe code vs perfect return-based code, the latter will 
be the same or faster.

Finally, empirically and practically, exception use rarely leads to "correct" 
code since people forget to actually handle them - thus comparisons are often 
skewed in the favor of exception-based code which has less error handling 
overall (and still ends up tends to end up slower due to the defensive overhead 
the compiler has to output).

Reply via email to