Implement exception handling correctly