[2042] in java-interest

home help back first fref pref prev next nref lref last post

throws declataration in Java/beta

daemon@ATHENA.MIT.EDU (Ken Arnold - Sun Labs)
Fri Sep 22 08:05:59 1995

Date: Thu, 21 Sep 1995 11:26:56 -0400
From: arnold@cocolat.East.Sun.COM (Ken Arnold - Sun Labs)
To: pambrose@weblogic.com
Cc: java-interest@java.Eng.Sun.COM

>Paul Ambrose sez:
>
>In beta Java, if object A extends object B, and both implement method
>foo(),  A.foo() *cannot* throw exception X unless B.foo() also
>throws X.  If you declare that A.foo()  throws X, the compiler
>will complain that B doesn't also throw X.

To be more precise, A.foo() cannot thrown an exception that is not in
B.foo()'s throws clause.  A.foo() can have its own throws clause that
is different from B.foo()'s as long as all elements of A.foo() would be
throwable by B.foo().  For instance, if B.foo() throws Gogin, then
A.foo() can be declared to throw either Gogin or any extended class of
Gogin.

>This means that you can NEVER throw an exception from a 
>toString() method because Object.toString() doesn't throw
>any exceptions.
>
>Is this correct? 

Yes.  Anything else would be a violation of the contract.  Analagously,
you cannot say that A.foo() returns an int if B.foo() returned a
short.

		Ken Arnold
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post