Handle error cases raising exceptions where necessary.
Merge pull request #6 from jonmagic/refactor-connection

Handle error cases raising exceptions where necessary.