Improved error handling

Error handling for internal and external classed have been improved. Error
codes list is extended. More exception cases are covered.

Logging mechanism will be added in the next draft.
Merge pull request #5 from evmarkov/master

Improved error handling