Sunday, 17 April 2011

What is use of throws keyword?

If the function is not capable of handling the exception then it can ask the calling method to handle it by simply putting the throws clause at the function declaration.
  public void parent(){
  try{
   child();
  }catch(MyCustomException e){ }
  }


  public void child throws MyCustomException{
   //put some logic so that the exception occurs.
  }

No comments:

Post a Comment