Added with, try, except and finally blocks to template.