title: Idiomatic way to handle template errors in golang
body: <p>Say I have a <code>html/template</code> like the following:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
      &lt;p&gt;{{SomeFunc .SomeData}}&lt;/p&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>and sometimes <code>SomeFunc</code> returns an error. Is there an idiomatic way to deal with this?</p>
  
  <p>If I write directly to the <code>ResponseWriter</code>, then a status code 200 has already been written before I encounter the error.</p>
  
  <pre><code>var tmpl *template.Template
  
  func Handler(w http.ResponseWriter, r *http.Request) {
      err := tmpl.Execute(w, data)
      // "&lt;html&gt;&lt;body&gt;&lt;p&gt;" has already been written...
      // what to do with err?
  }
  </code></pre>
  
  <p>Preferably I would return a status code 400 or some such, but I can't see a way to do this if I use <code>template.Execute</code> directly on the <code>ResponseWriter</code>. Is there something I'm missing?</p>