Theory on Forgetting and Generalization of Continual Learning