Two Laptop Bag*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "exceptions in Sun Watch "exceptions in Sun New topic
Author

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.
Stephanie
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Stephanie,
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."

HTH,
-Nate


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

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

Joined: Sep 29, 2000
Posts: 8521
Stephanie,
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: http://aspose.com/file-tools
 
subject: exceptions in Sun's documentation
 
Similar Threads
RMI Callback using socket pools
Not getting the bytes sent
Sockets vs URL Based classes
Using FTP in jsp
new to socket programming