check if error is defined

sometimes useful when reuse template
Merge pull request #427 from backender/patch-1

check if error is defined