Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exceptions -- How Do You Know Which?

 
Tasty Bread Products Inc.
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you know which exception(s) your methods should throw? Is there documentation and/or guidelines for this available as part of Sun's SDK?
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler informs you, in the case of "Checked" exceptions, if you do not enclode your code withing a try/catch block that catches the appropriate exception or it's superclass. Or fi you do not indicate that your method throws the exception or it's superclass. It is not a requiremen that you catch the other exceptions. You can check the API for more details.
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tasty Bread,
Javaranch has a naming policy. Please re-register with a name that complies with that policy so that you may continue to post here. Thanks.
 
Sreenivasa Majji
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java APIdocumentation tells about all the possible exceptions thrown by methods. However these are all checked exceptions, means that they will be checked at compile time. However the rumtime exceptions such as NullPointerException should be handled separately, unfortunately these are not available in API documentation.
Originally posted by Tasty Bread Products Inc.:
How do you know which exception(s) your methods should throw? Is there documentation and/or guidelines for this available as part of Sun's SDK?

[ January 16, 2002: Message edited by: sreenivasa majji ]
 
Shivaji Marathe
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can get a complete list of all the runtime exceptions by checking the Throwable \ Exceptions \ RuntimeExceptions hieratchy in the API.
java.lang package also lists all the exceptions and errors included in the package.
HTH
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic