Improved exception handeling for template