RSS Forums RSS

exceptions

Please support our Java advertiser: Programming Forums
Reply
Posts: 28
Reputation: Parsu7 is an unknown quantity at this point 
Solved Threads: 1
Parsu7 Parsu7 is offline Offline
Light Poster

exceptions

  #1  
Feb 28th, 2008
Suppose i try to instantiate an abstract class then a checked exception is thrown,but who handles it or how is it handled?
AddThis Social Bookmark Button
Reply With Quote  
Posts: 1,158
Reputation: javaAddict is just really nice javaAddict is just really nice javaAddict is just really nice javaAddict is just really nice 
Solved Threads: 163
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Veteran Poster

Re: exceptions

  #2  
Feb 28th, 2008
I don't think you can instantiate an abstract class.
There are 3 ways to do things:
The right way, the wrong way,
And The Object Oriented Way.

When you do things your way, make sure you don't forget the Object Oriented Way
Reply With Quote  
Posts: 28
Reputation: Parsu7 is an unknown quantity at this point 
Solved Threads: 1
Parsu7 Parsu7 is offline Offline
Light Poster

Re: exceptions

  #3  
Feb 28th, 2008
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?
Reply With Quote  
Posts: 1,158
Reputation: javaAddict is just really nice javaAddict is just really nice javaAddict is just really nice javaAddict is just really nice 
Solved Threads: 163
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Veteran Poster

Re: exceptions

  #4  
Feb 28th, 2008
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
There are 3 ways to do things:
The right way, the wrong way,
And The Object Oriented Way.

When you do things your way, make sure you don't forget the Object Oriented Way
Reply With Quote  
Posts: 28
Reputation: Parsu7 is an unknown quantity at this point 
Solved Threads: 1
Parsu7 Parsu7 is offline Offline
Light Poster

Re: exceptions

  #5  
Feb 28th, 2008
Thanks a lot.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 474 | Replies: 4 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:30 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC