Exception Handling (when to use it)

Daniel Barlow dan at coruskate.net
Tue Jul 31 01:11:04 BST 2007


Ovid wrote:
> Running out of records in a table is a normal condition.

This is most likely true (and from the way you describe it, certainly 
true in that case).  However, to answer the more general question you 
first need to define "normal", especially if someone else put the 
records there.  Suppose for example it was a static lookup table mapping 
country codes to names, and (let us say because the new DBA that only 
started work last week had truncated the table) there was no entry for
AT.  That's definitely a "can't happen" error, though the exception 
thrown should probably be CountryUnexpectedlyDoesNotExist rather than 
OutOfRecords.  AT is Austria, not Atlantis.

Let's take a more "borderline" case: you're reading from a network 
socket and the peer closes the connection halfway through sending you a 
message.  Normal?  Perhaps not?  Common?  Most definitely.  I guess my 
point is that although "exceptions are for exceptional situations" is 
definitely the right approach, you still really need some knowledge of 
the application level, not just the mechanisms, to decide what's 
exceptional and what's not.


-dan


More information about the london.pm mailing list