• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

exceptions in Sun's documentation

 
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Stephanie Grasson
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
reply
    Bookmark Topic Watch Topic
  • New Topic