Exception safety for template expansion