User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 456,515 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,817 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 352 | Replies: 2
Reply
Join Date: Oct 2007
Posts: 1
Reputation: tapannigam is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tapannigam tapannigam is offline Offline
Newbie Poster

Unhandled Excepton

  #1  
Oct 3rd, 2007
class A{
void process() throws Exception{
throw new Exception();
}
}
public class ExtendTest extends A{

void process(){
System.out.print("ExtendTest");
}
public static void main(String[] args) {
A a = new ExtendTest();
a.process(); //line 1
new ExtendTest().process(); // line 2
}
}
Why does this program gives an unhandled Exception at line 1? Line 1 and Line 2 are using same object.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2006
Location: in a dream
Posts: 127
Reputation: nschessnerd is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 6
nschessnerd's Avatar
nschessnerd nschessnerd is offline Offline
Junior Poster

Re: Unhandled Excepton

  #2  
Oct 3rd, 2007
Line 1 is an A object. a throws the error. When you declare an object like this i dont think the methods are overridden.
try ExtendTest a = new ExtendTest();
Reply With Quote  
Join Date: Aug 2007
Location: Adelaide, South Australia
Posts: 428
Reputation: darkagn will become famous soon enough darkagn will become famous soon enough 
Rep Power: 3
Solved Threads: 53
darkagn's Avatar
darkagn darkagn is offline Offline
Posting Pro in Training

Re: Unhandled Excepton

  #3  
Oct 3rd, 2007
You have assigned the variable a as an object of type A. A's process() method throws an exception. You need to wrap the line
  1. a.process();
in a try/catch block. Let me know if this hasn't helped.
Also,
  1. new ExtendTest().process();
doesn't make sense. I think what you want is
  1. ExtendTest et = new ExtendTest();
  2. et.process();
Reply With Quote  
Reply

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

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 3:59 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC