Add exception handling for output