There are 2 ways to deal with exceptions:
you can throw an exception:
public int foo() throws Exception{
}
here you pass back the exception instead of the desired int-value. the method above has to deal with the exception and probably to pass it on or to deal with it.
Other version is to catch the exception direct:
public int foo() throws Exception{
try{
}
catch(Exception oException){
oException.printStackTrace();
return -1;
}
}
in this case you catch the exception and often return a invalid int-value like -1. You can add a
finally { }
behind the catch to make sure certain operations are carried out no matter if the try/catch fails or not (e.g. closing file streams, making sure the database does not become invalid).