Entry for Saturday 4th July 2009
Tags: exception handlingInspiration: James Gosling
*James Gosling on localised exception handling* (paraphrased occasionaly):
When you try to open a file and it's not there, your coping strategy is really determined by what you were going for. Some guy (i.e. piece of code) miles away isn't going to know what to do. The code that tried to open the file knows what to do, whether it be trying a backup file, looking in a different directory, or asking the user for another filename.
Having one big catch clause on the outside really only works if your exception handling philosophy is simply to die. If you have an event loop, you can maybe cause that one event to just be tossed. If you have a plugin architecture, the enclosing environment could respond to a failure in the plugin by disabling it. But if you're not doing an event driven program or plugins, there isn't an outside place where you can take big hunks of functionality and saw them off.
It's good to have a last ditch catch clause though, specifially for a server, so that we can fail the offending request only.
In general, when you are writing a declaration in a throws clause, it is good to try to be as specific as possible because it gives more information to the context about exactly what went wrong.
Feed
carriagereturn is designed to be delivered every day to your favorite feed reader.
Here's the link to subscribe: