Tuesday, October 16, 2007


Exceptions again. I thought about them again after posting earlier about how pointless they are. I found some cases where they might be useful, but then I changed my mind.
For instance, I know it's truly elegant to write a = b + c * d - x++ with overloaded operators and just catch the exception instead of checking the result of each operation, but what if(a.has_error()) do_stuff_to(a.get_error()), something like aggresively_spit_message(a.get_error()->
get_human_readable_text_including_error_ \
type_and_operand_misvalue_and_any_releva \
And do whatever you like within the operators regarding operating on data with errors, just pass on the error.
I also know that even if you don't (can't) overload operators some methods must return useable objects, especially if you have immutable objects. Then either have mutable objects and pass them by reference, or make the error part of the object just as above. Duh.

No comments: