Thursday 29 November 2012

EXCEPTION HANDLING CONT1.........

THE FOLLOWING LEGAL CODE DEMONSTRATES A TRY WITH A FINALLY BUT NO CATCH:
  try{
  // do stuff
  } finally {
  //clean up
  }
  the following legal code demonstrates a try catch and finally;
  try {
  // do stuff
  }catch (SomeException ex) {
  // do exception handling
  } finally {
  // clean up
  }
  the following ILLEGAL code demonstrates a try without  a catch or finally:
  try {
  // do stuff
  }
  // need a catch or finally here
  system.out.println("out of try block");
  the following ILLEGAL code demonstrates a misplaced catch block::
  try {
  }
  // do stuff
  }
  // can't have code between try/catch
  system.out.println("out of try block");
  catch (Exception ex) {}
It is illegal to use a try condition without either a catch condition or a finally condition A try condition by itself will result in a compiler error any catch circumstances must immediately comply with the try avoid any finally condition must straight away comply with the last catch condition ( or it must quickly comply with the try avoid if there is no catch ). It is legal to take out either the catch condition or the finally circumstances but not both

No comments:

Post a Comment