Clear db connections when thread exits.
Print exceptions if they occur in thread.