java exception handling nested methods -


is design catch exceptions in method enclosed methods catch exception? example, in following code public method calls 2 private methods. private methods catch exception , print it:

/*the thing method call enclosed methods.*/ public object enclosingmethod() {     try     {        enclosedmethod1();        enclosedmethod2();     }     catch (exception e)     {        e.printstacktrace();     } }   private object enclosedmethod1() {     try      {        //some logic      }      catch (exception e)      {        e.printstacktrace();      } }  private object enclosedmethod2() {     try      {        //some logic      }      catch (exception e)      {        e.printstacktrace();      } } 

no, not design. , in case wrong, because surround calls of enclosedmethod1 , enclosedmethod2 in catch block, don't throw exception in these blocks, because exceptions cought!

especially not catch mother of exceptions, java.lang.exception.

but dependes. ask question: supposed happen when enclosedmethod1 encounters exception? should code continue executed? because if catch it, enclosedmethod2 still executed. should it? can't tell you, maybe can, because know enclosedmethod1 , enclosedmethod2 supposed do.

there no general answer question, because depends on requirements.

but always, take time think execption handling.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -