TITLE: Exceptions Should Be Exceptional
AUTHOR: Eugene Wallingford
DATE: December 29, 2014 3:27 PM
DESC:
-----
BODY:
Exceptions signal something outside the expected bounds of behavior
of the code in question. But if you're running some checks on
outside input, this is because you expect some messages to fail --
and if a failure is expected behavior, then you shouldn't be using
exceptions.
That is a snippet from
Replacing Throwing Exceptions with Notification in Validations,
a refactoring Martin Fowler published earlier this month. The
refactoring is based on an extraordinarily useful piece of software
design advice: exceptions should be unexpected. If something is
expected, it's not exceptional. Make your software say so. A
notification mechanism can carry as much information about system
behavior as exceptions and generally provides superior cohesion and
division of labor.
Over the last few years, I've come to see that is really a tenet of
good system design more generally. A couple of examples from my
university experience:
- If your curriculum depends on frequent student requests to
enable programs of study that faculty accept as reasonable,
then you should probably modify the curriculum to allow what is
reasonable. Not only are you gumming up the larger system with
unnecessary paperwork, you are likely disadvantaging students
who aren't savvy or cheeky enough to disregard the rules.
- If the way you pay for instruction and equipment doesn't match
the stated budget, then you should change the budget to reflect
reality. If you don't control the writing of the budget, then
you should find ways to communicate reality to the budget
writers whenever possible. Sometimes, you can work around the
given budget to accomplish what you really need for a long
time. But over time the system will evolve in response to
other external forces, and you reach a point where the budget
in no way reflects reality. A sudden change in funding can put
you in a state of real crisis. Few people will be able to
understand why.
People sometimes tell me that I am naive to think complex systems
like a university or even a curriculum should reflect reality
closely. Programming has taught me that we almost always benefit
from keeping our design as clean, as understandable, and as truthful
as we can. I am pragmatic enough to understand that there are
exceptions even to this tenet, in life and in software. But
exceptions should be exceptional.
-----