Exception handling and error logging