Exception handling protocol for methods

Posted by athena on Stack Overflow See other posts from Stack Overflow or by athena
Published on 2010-06-05T10:23:03Z Indexed on 2010/06/05 10:32 UTC
Read the original article Hit count: 269

Filed under:
|
|

Is there any specific protocol for handling exceptions in public methods? Consider this eg.

public int someMethod()
{
  try{
  code that might throw an exception    
  }
  catch(Exception e)
  {
     log the exception
  }
}

Say that this method might throw an ArrayIndexOutOfBoundsException. So, is it correct to handle this Exception in the method itself (as in the example) or throw it and assume that the calling method will handle the Exception?

© Stack Overflow or respective owner

Related posts about java

Related posts about exception-handling