Hi David:

Please correct me if I misunderstand you, but here's what it seems you are doing:

1. Create a class MyClass with a public method myMethod and a constructor which
throws an exception.
2. Create an *object* oneclass of class MyClass. You havent stated that oneclass is
actually of class MYClass but i assume it has to be since you are using MyClass's
constructor. (I don't see any inner or subclass here and therefore fail to see what
overriding you are talking about..)

Now here's where I see a compiler ccomplain: when you create this object oneclass,
you need to take care of the exception that this creation could throw (according to
the constructor for MyClass). So you need to say:
try{
     oneclass=new MyClass("Test", 1);
     //etc.etc.
}
catch(Exception e){
//deal with the exception here..
}

Unless of course you actually mean to say:
public OneClass extends MyClass, and oneclass is meant to be an object of class
OneClass?? In which case of course overriding myMethod makes sense inside this
subclass..

(.. I hesitated a while before writing this because I felt I must be wrong in
understanding you somewhere.. ..!)

Geeta
PS Finally, what is line 32? If i am right, it should read: "oneclass=new
MyClass("Test", 1);"..

David V�squez Estrada wrote:

> Hi,
>
> The error is an compilation error is not execution error, and the compiler
> (JBuilder4) shows me only the following compilation error:
>
>     Error #: 360 : unreported exception: java.lang.Exception; must be caught or
> declared to be thrown at line 32, column 28
>
> The class has this form, with a constructor who throws an exception:
>
>    public MyClass
>    {
>             MyClass(String str, int type) throws Exception {};
>             public int  myMethod(int i) {return i;};
>     }
>
> When I try to override the method myMethod:
>
>     oneclass=new MyClass("Test", 1)
>         {
>             public int myMethod(int i) {return i++; }
>         }
>
> Seems to be that is not possible to override a method when the constructor
> throws an exception.
> I have already tried to make try-catch when creating this inner class, but it
> doesn' work,
>
> David
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to