fixed example code for error handling