more robust exception handling