Add exception handling to main.