3 ms·
The "exceptions should be exceptional aka rare" line sounds aspirational, but I wonder how true it is if you survey the general landscape of actual libraries.
by infogulch 5y ago
The "exceptions should be exceptional aka rare" line sounds aspirational, but I wonder how true it is if you survey the general landscape of actual libraries.
- IshKebab 5y agoProbably not that rare to use exceptions but I imagine it is very rare to use exceptions for normal flow control - that is, to continue execution after an exception. It's a common pattern in Python but not C++. I've done it exactly once and I ended up removing it because it makes debugging exceptions that you care about really annoying.
- jolmg 5y ago> but I imagine it is very rare to use exceptions for normal flow control - that is, to continue execution after an exception Exceptions are at least a very central part of the normal flow control of parser combinator libraries.
- gpderetta 5y agoYou are not wrong. The exceptional exception guideline feels circular. I would use exceptions significantly more if I could rely on their performance.
- randyrand 5y agoOn top of that, you never know the context in which your users will call your library. Are you encoding a single file on a local machine? Or 1000 files on some HPC 128-core machine? Do we really want to be in a world where all libraries need to be written with and without exceptions since we can't know the context they'll be used in?
- wvenable 5y agoWhy is the error occurring in the first place? In my opinion, exceptions/errors should be rare. If it's a software problem, it should eventually be fixed. If it's an infrastructure problem, it should be fixed. It's not just something that should continue to happen without any mitigation what so ever over time.
- kllrnohj 5y agoNot all errors have "fixes". If I navigate to "https://news.ycombinator.com/nope https://news.ycombinator.com/nope" it returns an error to me. Is that a software problem or an infrastructure problem? And what's the fix? How do you "fix" a bad input to the system from an external actor? So no, errors/exceptions are not rare depending on the context. So now do you use exceptions and accept that it doesn't scale across core counts? Or do you use return values and accept that it just makes all your code slower in all cases? 1% error rate sounds like a lot. But really how many HTTP errors do web servers return on average? Or other such systems? It's definitely more than 0%, and those services also scale nicely across multiple cores, so... Now we're just bikeshedding over the example numbers, not the core issue.
- deleted 5y ago[deleted]