2 ms·
> Firstly I'm not happy with using exceptions for something like this. Exceptions signal something outside the expected bounds of behavior of the code in questi
by twic 12y ago
> Firstly I'm not happy with using exceptions for something like this. Exceptions signal something outside the expected bounds of behavior of the code in question.
I've been hearing this line since the '90s. I've never heard a justification for it, or a rigorous explanation of what "expected" means.
Exceptions are a language construct, like variables, classes, and for loops. As with those other constructs, use them when it results in a program which makes sense. But that's a judgment you can only make on the program, not on the construct.
- jerf 12y agoThe following will sound cynical, but I'm serious. The "justification" is nothing more and nothing less that the original creators of the exception intended it to be used that way. It's the same reason people still quote Alan Kay as if his opinions about "object orientation" apply to everything that happens to wear that label 40 years later, and as if his opinion is some sort of controlling vote over whether something is "truly" OO or worse, good OO. While I am all about respecting our predecessors and their good work (probably more so than most HN folk, though my respect rarely shows on HN itself; much of it is on topics not HN-related), I dislike that sort of fealty to their opinions. It shuts down thought and conversation. Whether exceptions should be "exceptional" should be something discussed carefully, not simply true by definition. Personally I'd observe that due to immense variances in exception semantics and performance in all the various runtimes and languages of the world there isn't a blanket statement you can make about whether that is true; for instance, C++ and Python have radically different criteria for what an "exception" should be, written into their nature, and just dogmatically repeating "exceptions should be exceptional" won't help you understand anything about the details of either language, or how they differ.
- dragonwriter 12y ago> I've never heard a justification for it, The usual justification I've heard is that it is superior for the flow of operation for expected cases to be clear from inspecting the code, and the use of exceptions breaks that up. > or a rigorous explanation of what "expected" means. This is a problem. I have my own construction of what it makes sense for "expected" to mean in this context [0], but its not clear to me that that's what others offering this rule necessarily do mean by "expected", it usually seems to be fuzzier (which is problematic.) > Exceptions are a language construct, like variables, classes, and for loops. As with those other constructs, use them when it results in a program which makes sense. But that's a judgment you can only make on the program, not on the construct. I generally agree, but I think that -- with the understanding of "expected" relating to the advertised constraints/expectations of the unit of code in question -- its a fairly good rule of thumb for when using exceptions results in code that makes sense. [0] https://news.ycombinator.com/item?id=8746874 https://news.ycombinator.com/item?id=8746874