DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   exceptions (http://www.daniweb.com/forums/thread111392.html)

Parsu7 Feb 28th, 2008 2:02 pm
exceptions
 
Suppose i try to instantiate an abstract class then a checked exception is thrown,but who handles it or how is it handled?

javaAddict Feb 28th, 2008 2:09 pm
Re: exceptions
 
I don't think you can instantiate an abstract class.

Parsu7 Feb 28th, 2008 2:19 pm
Re: exceptions
 
Ok that thing i know ,i just want to throw an Instantiation Exception and wants to know who handles it and how is it handled . Now the other thing which i want to know is that can we avoid an exception through throws clause?

javaAddict Feb 28th, 2008 2:32 pm
Re: exceptions
 
public void foo() throws Exception {
  //something happens and an exception is being thrown
}
With the throws you don't avoid the exception. By adding throws you don't have to catch it, but it is thrown to the method that calls foo. Meaning that you have to write something like this:
public void hoo() {
  try {
    foo();
  } catch (Exception e) {
  }
}
You can omit try-catch by adding throws Exception at the declaration of hoo() but you don't avoid it because it is thrown to the one that calls hoo(). You can do that until you reach main() where you will eventually have to catch it in the end

Parsu7 Feb 28th, 2008 2:39 pm
Re: exceptions
 
Thanks a lot.


All times are GMT -4. The time now is 9:02 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC