Robot Motion and Task Learning with Error Recovery