title: How should I capture multiple similar exceptions in such a case?
body: <p>For example, I am parsing an xml file element, and all 4 elements are required. My code this like this with minidom library:</p>
  <pre><code>id = pattern.getElementsByTagName(&quot;id&quot;)[0].firstChild.data
  name = pattern.getElementsByTagName(&quot;name&quot;)[0].firstChild.data
  trigger = pattern.getElementsByTagName(&quot;trigger&quot;)[0].firstChild.data
  test = pattern.getElementsByTagName(&quot;test&quot;)[0].firstChild.data
  </code></pre>
  <p>If the xml document lack any of the 4 tags, I want to throw an IndexError exception. Should I use 4 try ... except blocks to capture each element exception, or I should just capture all the 4 similar exceptions in one big block? The benefit of capturing individual errors is that I can print out more explicit error message regarding the lack of a specific xml element, but it looks verbose. Is there a good practice here?</p>
  <pre><code>try:
     id = pattern.getElementsByTagName(&quot;id&quot;)[0].firstChild.data
  except IndexError:
     raise IndexError('id must exists in the xml file!')
  try:
     name = pattern.getElementsByTagName(&quot;name&quot;)[0].firstChild.data
  except IndexError:
     raise IndexError('name must exists in the xml file!')
  try:
         test = pattern.getElementsByTagName(&quot;test&quot;)[0].firstChild.data
      except IndexError:
         raise IndexError('test must exists in the xml file!')
  try:
         trigger = pattern.getElementsByTagName(&quot;trigger&quot;)[0].firstChild.data
      except IndexError:
         raise IndexError('trigger must exists in the xml file!')
  </code></pre>
  <p>OR</p>
  <pre><code>try:
    id = pattern.getElementsByTagName(&quot;id&quot;)[0].firstChild.data
    name = pattern.getElementsByTagName(&quot;name&quot;)[0].firstChild.data
    trigger = pattern.getElementsByTagName(&quot;trigger&quot;)[0].firstChild.data
    test = pattern.getElementsByTagName(&quot;test&quot;)[0].firstChild.data
  except IndexError:
    raise IndexError('id, name, trigger and test must exist in the xml file!')
  </code></pre>
  <p>Which one is better or both are not great?</p>