[2206] in java-interest
Re: throws declataration in Java/beta
daemon@ATHENA.MIT.EDU (Ken Arnold - Sun Labs)
Tue Sep 26 22:17:58 1995
Date: Fri, 22 Sep 1995 16:04:34 -0400
From: arnold@cocolat.East.Sun.COM (Ken Arnold - Sun Labs)
To: cjl@Eng.Sun.COM
Cc: java-interest@java.Eng.Sun.COM
>From: Christopher Lindblad <cjl@Eng.Sun.COM>:
> From: arnold@cocolat.East.Sun.COM (Ken Arnold - Sun Labs)
>
> A method cannot throw an exception type not declared in its throws
> clause. This is good. You now know which exceptions can be thrown by
> a method.
>
>Then shouldn't any method that uses the "new" operator be required to either
>catch java.lang.OutOfMemoryError or declare it in its throws clause?...
>
>Also, shouldn't any method that uses arrays or accesses an instance variable
>or method on another object either catch java.lang.NullPointerException or
>declare it in its throws clause?...
>
>Perhaps these should be considered "universal" exceptions, in that one should
>assume that all methods throw them. In that case, shouldn't
>InterruptedException be counted as a "universal" exception too?
You are absolutely correct. In fact, Java has such "universal"
exceptions, such as NullPointerException and OutOfMemoryError. And you
don't have to declare them, since they can happen anytime to any code.
These are all extensions of the RuntimeException class, which do not
have to be declared in signatures.
And, no, InterruptedException is not and should not be one of them,
since it is only of interest to the thread involved. Otherewise
InterruptedException would cause thread death, since an unhandled
exception in run() will result in run() terminating, which stops the
thread. This is probably not the expected behavior.
Ken Arnold
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com