Only check connection where we actually use it.
Changed exception hierarchy.