Exception handling and logging