Only use a single exception type.

Also check for socket errors in `connect` and add some comments.