Throw exception when template document is invalid