Add exception handling

Added exception handling and mailing for failures.