Thread View: news.software.nntp
1 messages
1 total messages
Started by Robert
Sun, 11 Mar 2007 01:10
Re: Why does Java require the throws clause? Good or bad language design?
Author: Robert
Date: Sun, 11 Mar 2007 01:10
Date: Sun, 11 Mar 2007 01:10
48 lines
3437 bytes
3437 bytes
In article <20070208111322.GB5007@morgenes.shire.sytes.net>, Robbert Haarman
<comp.lang.misc@inglorion.net> wrote:
>On Thu, Feb 08, 2007 at 10:44:18AM +0000, Bent C Dalager wrote:
>> And, of course,
>> public void foo(Object... args) throws Throwable
>> may be just the silver bullet we are looking for . . .
>
>It is true that this removes the effort of changing the declaratiens in
>response to refactoring, but Java will still impose burdens on the
>programmer. First, they have to actually type "Object" before every
>argument and "throws Throwable" after every method declaration.
throws Throwable means your very design is incorrect
as you are entirely missing the granularity of your errors.
You'll never be able to successfuly recover
and forget about reattempting the operation
on a fine grained level as you will be thrown
several layers up.
>Secondly, if you actually want to use these arguments and throwables,
>you will have to downcast them to another class, because Object and
>Throwable probably don't have the methods and fields you need. This
>requires more typing. It also incurs a performance penalty, because the
>casts will be checked at run time. In the end, you get the worst of
>dynamic typing and the worst of mandatory declarations, all in one
>program.
A BASIC rule in object oriented programming:
DO NOT USE CASTS.
Unless it is absolutely unavoidable.
>Regards,
>
>Bob
>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"The most important job is not to be governor,
or first lady in my case."
--- Adolph Bush,
Pella, Iowa,
as quoted by the San Antonio Express-News, Jan. 30, 2000
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads