Exception - special conditions that change the normal flow of program execution.
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
try{
//protected block
}catch(Datovy typ výjimky){
//exception handling
}finally{
//this code it execute every time
}
Block finally it will execute always.
Exception chaining
public void configure() throws ConfigurationException{
try{
...
...
}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