FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Development Tools
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
November 01, 2005
Pragmatic Exceptions

Benjamin Booth
November 2005 Pragmatic Exceptions.
November, 2005: Pragmatic Exceptions


Tip #3: The Bird's-Eye View Knows What To Do

The best view of your program is the bird's-eye version. The top of the execution stack is the best context for deciding what to do with the exception-hot potato.

It's also no accident that the higher in the stack you go, the closer you get to the application user's perspective. Because this is the perspective you (as the exception catcher) should be most concerned about, it follows that the top of the execution stack is where the best exception handling can occur.

If "you're it" as the exception catcher for the job, your options include:

  • Handling it in a nonfatal way.
  • Exiting the application.
  • Eating it (ignoring it).

If the current exception doesn't seem like an application killer but you're not sure, play it safe and follow Tip #1—If In Doubt, Throw It Out. This assumes you're not the highest-level catcher. You might try Refactoring for exceptional clarity to give yourself more certainty.

Exiting the application is an option, but this is reserved for the most fatal of errors. Assuming it's not one of these and knowing exceptions may be poisonous, you're left handling the exception somehow. The rubber finally meets the road. Here, you have three kinds of choices:

  • Give users an obvious message.
  • Write an output message (cmd line or log).
  • Punt it all and quit writing software that sucks.

In picking from the first two options, you can Make Only the Actionable Obvious (Tip #4; available in next month's issue) to give us a simple heuristic for making the right decision.

—Benjamin Booth
benjamin.booth@gmail.com

TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK



 




United Business Media LLC
Comments about the web site: webmaster@ddj.com