Tuesday, February 17, 2009

to throw and catch exceptions


Exceptions should be thrown as early as possible. As soon as you detect the error condition, the exception needs to be generated. If you wait for too long, it becomes more difficult to analyze the problem. Similarly, exceptions should be caught in those contexts where some corrective action can be taken. Otherwise, pass them up the hierarchy until you have enough information so that you can effectively deal with them.

Thus, we can say "throw exceptions early" and "catch exceptions late".



No comments: