This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Java in General and the fly likes exceptions in Sun's documentation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "exceptions in Sun Watch "exceptions in Sun New topic

exceptions in Sun's documentation

Stephanie Grasson
Ranch Hand

Joined: Jun 14, 2000
Posts: 347
Hi all,
Has anyone else noticed some discrepancies in Sun's documenation of exceptions?
For example, I'm using the Socket constructor which takes two arguments: (1) a String which is the host and (2) and int which is the port number.
The declaration of this method in the documentation is
public Socket(String host, int port) throws UnknownHostException, IOException
However, if you read down a few lines, under the Throws header it says the method throws IOException and SecurityException.
Must I catch all three? If so, why aren't all three included in the throws part of the declaration? I am a little confused.
Thanks in advance.
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

No... this is not an error in documentation... SecurityException is a RunTimeException, thus it is an unchecked exception and does not have to be declared under the throws clause of the method, or caught in a try/catch block.
In the JLS this is mentioned in section 11.2 :

"The unchecked exceptions classes are the class RuntimeException and its subclasses, and the class Error and its subclasses. All other exception classes are checked exception classes. The Java API defines a number of exception classes, both checked and unchecked. Additional exception classes, both checked and unchecked, may be declared by programmers. See �11.5 for a description of the exception class hierarchy and some of the exception classes defined by the Java API and Java virtual machine."


Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Stephanie Grasson
Ranch Hand

Joined: Jun 14, 2000
Posts: 347
Thanks for your reply. I should have looked at the base class for SecurityException before posting. Just being lazy I guess.
Thanks again.
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Look at it this way, you were REALLY doing a favor for the rest of us!!! See, I got a review on unchecked exceptions AND learned a little more about SecurityExceptions.
So this was really more in the line of Altruism (NEVER laziness).

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: exceptions in Sun's documentation
It's not a secret anymore!