Error handling in list sorting