3 ms·
This article can be seen as a very good explanation of why exceptions are a valuable feature for a language. In python, mentioning one of the languages exposed
by aurelianito 12y ago
This article can be seen as a very good explanation of why exceptions are a valuable feature for a language. In python, mentioning one of the languages exposed in the article, I would return the created object and throw an exception on error.
- sparkie 12y agoThis has the same properties as B in his examples though - one can simply fail to catch the exception and the same problems arise. I actually much prefer the B solution (or a variation, where instead of returning error codes, you pass in an exception handler function), as opposed to exceptions which are "hidden" from the API and rely on users to read documentation (hint: most people don't, until they find out the hard way).
- aurelianito 12y agoIt is different. An excepction decouples the place where errors must be handled from where the required object will be used. A closer example would be if the function received a function pointer or, even better, a continuation to be invoked if an error ocurrs.