943,692 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 636
  • Java RSS
Feb 28th, 2008
0

exceptions

Expand Post »
Suppose i try to instantiate an abstract class then a checked exception is thrown,but who handles it or how is it handled?
Similar Threads
Reputation Points: 9
Solved Threads: 1
Light Poster
Parsu7 is offline Offline
29 posts
since Feb 2008
Feb 28th, 2008
0

Re: exceptions

I don't think you can instantiate an abstract class.
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,258 posts
since Dec 2007
Feb 28th, 2008
0

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?
Reputation Points: 9
Solved Threads: 1
Light Poster
Parsu7 is offline Offline
29 posts
since Feb 2008
Feb 28th, 2008
0

Re: exceptions

Java Syntax (Toggle Plain Text)
  1. public void foo() throws Exception {
  2. //something happens and an exception is being thrown
  3. }
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:
Java Syntax (Toggle Plain Text)
  1. public void hoo() {
  2. try {
  3. foo();
  4. } catch (Exception e) {
  5. }
  6. }
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
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,258 posts
since Dec 2007
Feb 28th, 2008
0

Re: exceptions

Thanks a lot.
Reputation Points: 9
Solved Threads: 1
Light Poster
Parsu7 is offline Offline
29 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: triangle, rectangle and TwoDShape
Next Thread in Java Forum Timeline: How to call a class that draws a circle in a MouseMoved method ??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC