Thread: JAVA Exception
View Single Post
  #4 (permalink)  
Old Sep 9th, 2007, 20:19
abalfazl abalfazl is offline
Junior Member
Join Date: Sep 2005
Location: Beyond the seas there's a town,In hand of each child a branch of insight lies,I shall build a boat.
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Re: JAVA Exception

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

Last edited by karinne; Sep 10th, 2007 at 13:15. Reason: Please use [ code ]...[ /code ] tags when displaying code.
Reply With Quote