Add exception handling to main block