title: Catching Exceptions not related to XML while SAX parsing in Java?
body: <p>I am not educated in catching exceptions in Java so this might be a trivial question:<br>
  I parse an XML file, and in the method for endElement I have:</p>
  
  <pre><code>@Override
  public void endElement(String uri, String localName, String qName) throws SAXException {
  
     if (qName.equals("manufacturer")) {
              newManufacturer = false;
              String venueName = manufacturerBuilder.toString();
              event.setVenueName(venueName);
     }
  }
  </code></pre>
  
  <p>If event is null, my program crashes. What I'd like to do is add a couple of instructions for an orderly shutdown in this case (closing db connections etc).  </p>
  
  <p>Of course I can do:  </p>
  
  <pre><code>try{
     event.setVenueName(venueName);
  }
  catch (NullPointerException e){
     db.close();
  //etc
  }
  </code></pre>
  
  <p>But I have many of these exceptions to catch in the methods of the parser. Can't I just put a try - catch at a higher level that would catch any kind of exception while parsing (such as the one above)? But where exactly?  </p>