connection exception optional, extracts code