4 ms·
I once had an argument about usage of exceptions for flow control and I mentioned this principle. The developer replied, mostly tongue in cheek to be fair: We
by reallydontask 7y ago
I once had an argument about usage of exceptions for flow control and I mentioned this principle.
The developer replied, mostly tongue in cheek to be fair:
Well, it doesn't astonish me
- ArnoVW 7y agosubjectiveness aside, exceptions generally are relatively expensive.. In Java : http://java-performance.info/throwing-an-exception-in-java-is-very-slow/ http://java-performance.info/throwing-an-exception-in-java-i... In C# : https://docs.microsoft.com/en-us/dotnet/standard/exceptions/best-practices-for-exceptions https://docs.microsoft.com/en-us/dotnet/standard/exceptions/... In C++ : https://pspdfkit.com/blog/2020/performance-overhead-of-exceptions-in-cpp/ https://pspdfkit.com/blog/2020/performance-overhead-of-excep...
- Doxin 7y agoThat seems to me to be an implementation detail though. There's no real reason you can't have a compiler that converts exception-throwing-code into error-code-returning-code. That'd basically cost you the performance of a couple if-statements per function call return, which doesn't seem too excessive to me. Of course most languages don't implement exceptions this way and I'm sure there's a good reason for it but you can still choose -- as a language implementor -- to have cheap exceptions.
- reallydontask 7y agoThat's one of the arguments I used. We used C# and he actually did some noddy perf tests the conclusion of which where: It's slower but only adds 0.01 s as compared to the a version not using exceptions. This was about 3 orders of magnitude slower (probably more under load would be my guess) +1 for all the extra work to prove to himself that he had taken the right approach. -10 For refusing to listen, ignoring data and cherry picking articles on C about exception handling (Of course they're not going to use exceptions, they don't exist)