javaexceptionsaxsaxparsersaxparseexception

Exception Handling: Will parent class exception catch child exception too


SAXException is extended by SAXNotRecognizedException, SAXNotSupportedException.

try {
  //do Something
} catch(SAXException e) {}
  catch(ParserConfigurationException pce) {}

if lets say 'do something' has some code that throws SAXNotRecognizedException or SAXNotSupportedException and if that happens then nothing should happen. If SAXNotRecognizedException occurs then will nothing happen since its a empty block. Similarly for ParserConfigurationException. Right now, even though I say do nothing for ParserConfigurationException then also a exception for ParserConfigurationException is thrown.

I basically want it to do nothing when SAXNotRecognizedException or SAXNotSupportedException occurs.


Solution

  • Yes parent exceptions will catch child exceptions as well. A known example is when you catch Exception. This try block will catch all sorts(child) exceptions such as NullPointer etc.