Add exception handling

Add exception handling and mailing.