Hi!
http://java.ztor.com/fundamental/main/
Handling Exceptions
You can handle exception otherwise you must declare it. Also you can handle some exceptions and declare others.
Handle Exceptions
- Code: Select all
public void myMethod() {
try {
. . .
}
catch (ExceptionType1 e) {
. . .
}
catch (ExceptionType2 e) {
. . .
}
finally {
. . .
}
Declare Exceptions
- Code: Select all
public void myMethod() throws ExceptionType1,ExceptionType2 {
. . .
}
May someone explain more about difference between these?When do we use declare exception?When to use handle exception?
Quote:
|
You declare that a method throws an exception if the problem can't be handled in the method. You handle the exception in the method if you can handle the error and continue with the method.
|
May show this by an example?
Thanks in advance