Exception handling and code formatting