Sunday, January 24, 2010

Exception handling

Exception - special conditions that change the normal flow of program execution.

Exception hierarchy

Exception hierarchy

Your exception extend Exception.

Type of exception

  • Checked exception
  • Unchecked exception

Standart checked exception

  • IllegalArgumentException
  • IllegalStateException
  • NullPointerException
  • IndexOutOfBoundsException
  • ConcurentModificationException
  • UnsupportedOperationException
  • AritmeticException
  • NumberFormatException

Exception handle

//protected block
}catch(Datovy typ výjimky){
//exception handling
//this code it execute every time

Block finally it will execute always.

Exception chaining

public void configure() throws ConfigurationException{
}catch(FileNotFoundException e){
throw new ConfigurationException("Config file not exists.",e);
}catch(PropertyMissingException e){
throw new ConfigurationException("Missing argument.",e);
}catch(InvalidFormatException e){
throw new ConfigurationException("Unknown argument",e);

Exception mesage

public IndexOutOfBoundException( int lowerBound, int upperBound, int index){
super ("Lower bound:" + lowerBound +
", Upper bound: " + upperBound +
", Index: " + index);

No comments:

Post a Comment