Hi Chigger:
Thanks for the compliment. As far as resources on the subject go, the best
I've read (and I'm a .NET book junkie) has to be Jeffrey Richter's Applied
..NET Framework Programming
http://www.amazon.com/exec/obidos/tg/detail/-/0735614229/qid=1079041773/sr=8
-1/ref=pd_ka_1/102-0030869-0684145?v=glance&s=books&n=507846
The whole book is pure gold and if you have been doing Windows programming
for any amount of time, Richter is one of the most respected names in the
field so I take his suggestions seriously. He goes on a tirade about not
trapping System.Exception for instance, and has a lot of guidelines for what
Exception handling is and how to employ it.
I really oversimplified version of his thesis is this:
Don't trap exceptions just to trap them. You should be as specific as
possible, and do something when you trap them, namely respond to them.
Don't trap things you aren't going to respond to. So, if you had a proc
that only had MessageBox.Show("Hello"); there's no need to trap an
IndexOutofRangeException for instance. However, there are times when you
know that something 'could' happen, like trying to reference a file on a
network - the other machine could be down, the network could be down, your
network cable could be unplugged. So you may want to trap FileNotFound
exception (or, to be defensive, check for the existence in advance). WIth a
DB Connection on the other hand, you can't tell if you can open it without
trying to open it, so you'll want to trap this. When opening a file, you
can't tell if you can open it or not until you try...someone else may be
using it so trap that specific exception to.
And you don't have to try to trap things in every code block. That can lead
to misleading return values and hide serious logic problems. So often
you'll want to let the caller handle the problem (particularly if you are
developing code libraries).
He also recommends using Finally blocks very liberally b/c they are
guaranteed to execute.
Anyway, there are entire chapters of books dedicated to the subject so I
can't really synthesize it in one post. I'd really recommend picking up his
book b/c even though it's not a CF book, it's discussion of the theorectical
and inner workings of the framework are pure gold and you'll definitely get
a deeper understanding of what's going on behind the scenes.
HTH,
Bill