Error handling and validation