Adding try..catch handlers for the environment termination code

fixes #33