[3288] in java-interest

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

Re: I want to shoot myself!!!!!!!!!!!!!!!!!!

daemon@ATHENA.MIT.EDU (Ken Arnold - Sun Labs)
Mon Nov 6 14:07:00 1995

Date: Mon, 6 Nov 1995 10:25:07 -0500
From: arnold@cocolat.East.Sun.COM (Ken Arnold - Sun Labs)
To: java-interest@webrunner.neato.org

What you get from declaring something as a RuntimeException is the
ability to throw it without declaring that you do so.  In other words,
it is a way to *not* document what you throw.  When is this good?
Well, when is it ever good to avoid documenting a method's behavior?
The answer is essentially "hardly ever".  Arthur's "everyone does it,
and everyone knows that everyone does it" exception is the only valid
out, as long as everyone *means* everyone.

Arthur's point is well taken if it is taken carefully.  You would be
hard pressed to find exceptions you have just discovered that could
happen, say, in OutputStream.write().  So if you cut yourself enough
slack to extend RuntimeException somewhere, you are probably cutting
enough extra slack to hang yourself.

You have already seen the danger in the "I don't need to catch it"
approach -- you suggested MalformedRegexp as a good example of it, and
it isn't.  David Foster pointed out that it depends where the regexp
came from.  In other words "some need to, some don't".  The ones who
need to catch it need to know you throw it, so you should put it in
your throws clause and not extend RuntimeException for it.

Edith Au said it right: you extend RuntimeException when you are
creating an error in the virtual machine runtime.  Which you probably
aren't.  Otherwise you should extend Exception.

		Ken Arnold

-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

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