Implement error checking for cat function