classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Declaring RuntimeExceptions?


From: Eric Blake
Subject: Re: Declaring RuntimeExceptions?
Date: Thu, 11 Sep 2003 17:55:54 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624

I agree with Tom that we should not declare unneeded exceptions, even when Sun does.

Not all compilers emit RuntimeExceptions into the .class file to begin with. Reflection data is not guaranteed to be the same between two compilers, even if you DO declare the RuntimeExceptions, because compilers have the right to optimize for size and omit wasting the space on the useless declaration information. Therefore, code relying on the declared RuntimeExceptions returned by reflection is just asking for problems.

David Holmes wrote:
Standard practice - as epoused by various books and articles from
various source related to Sun - is to not declare RuntimeExceptions on
a throws clause. Such exceptions should be documented in the javadoc
only.

However, the reflection issue is not something I was aware of. If
indeed reflection returns all declared throwables whether runtime
exceptions or not, then there will be a behavioural difference -
though not one that anybody should ever be relying upon.

This situation is also clouded by the default rules for inheriting
@throws documentation comments, which will only inherit comments for
exceptions that are listed in the throws clause. The way around this
is to not declare the exception but instead to the use @inheritDoc to
force the inheritance of the doc comment eg:

   @throws someRuntimeException address@hidden

but some people may start declaring the runtime exceptions just to
inherit the doc comments.

David Holmes



_______________________________________________
Classpath mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/classpath


--
Someday, I might put a cute statement here.

Eric Blake             address@hidden





reply via email to

[Prev in Thread] Current Thread [Next in Thread]