replace trap with exception handling to gracefully exit on sigint