Exceptions…Lets Handle it.

It is always advisable to handle EXCEPTIONs properly in your code(provided that the programming language has a support for it). Its a standard practice and the best way to handle surprised or “MY God!!!” type errors .

So you must be aware that its better to be specific while handling errors. Instead of going for a big basket (Exception class in general) choose a specilised exception(for example IOException). Because this will help you not only tracking where the bug is but also reduce debugging time.
Now thats not the point of this topic. When you are very much specific that a particular type of error is going to occur, why don’t you validate instead of going for exception way!!! That may be a more accurate way of not letting the exception to occur. If you know that divide by zero exception is going to occur in your code, then validate the number before hand and pass the non zero arguments so that you will save execution time.

So its completely depends on the requirement, study it properly and go for some validation (as applicable) rather putting more efforts on exception for the same.

Happy Coding…Keep smiling

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s