File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exceptions -- checked versus unchecked.... and which ones are which

 
Janeice DelVecchio
Saloon Keeper
Posts: 1800
12
Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, so I understand that a checked exception results in a compile time error, and unchecked exceptions result in runtime errors.

I think I understand why (because the compiler "checks" for the checked exceptions... if you're running, you've been checked?).....

I remember the common runtime exceptions.... null pointer, class cast, arithmetic. And the common compiler time exceptions.... IO, class/method not found, SQL.

Now I'm looking at the API. There's like fifty of each. How many of these do I really need to know? I mean, is UnsupportedFlavorException really on the exam (I know the compiler hates cherry flavor, but come on!)?

I have the K&B SCJP6 book.... I just can't find any list of ones I need to memorize. And I'm not sure how much is extensive API memorization versus just knowing conceptually which one is going to cause a compile/run time error (and thus which needs to be caught).

Any tips?
 
Mohamed Sanaulla
Saloon Keeper
Pie
Posts: 3159
33
Google App Engine Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Janeice DelVecchio wrote:Okay, so I understand that a checked exception results in a compile time error, and unchecked exceptions result in runtime errors.

I think I understand why (because the compiler "checks" for the checked exceptions... if you're running, you've been checked?).....


Checked exception- Are thrown when the program is executing and they need to be supported by throws clause or the try...catch block. Any attempts to compile the code without any of these- throws/try...catch for Checked exceptions would result in a compiler error. But Checked exceptions itself don't result in a compile time error.

Same goes with Unchecked exceptions- These need not be handled by the code as they are usually unexpected errors/exceptions. This link briefly explains the two.

Janeice DelVecchio wrote:
I remember the common runtime exceptions.... null pointer, class cast, arithmetic. And the common compiler time exceptions.... IO, class/method not found, SQL.

Now I'm looking at the API. There's like fifty of each. How many of these do I really need to know? I mean, is UnsupportedFlavorException really on the exam (I know the compiler hates cherry flavor, but come on!)?

I have the K&B SCJP6 book.... I just can't find any list of ones I need to memorize. And I'm not sure how much is extensive API memorization versus just knowing conceptually which one is going to cause a compile/run time error (and thus which needs to be caught).

Any tips?

From the Objectives in the Flow Control Section:
Section 2 Flow Control wrote: Recognize situations that will result in any of the following being thrown: ArrayIndexOutOfBoundsException,ClassCastException, IllegalArgumentException, IllegalStateException, NullPointerException, NumberFormatException, AssertionError, ExceptionInInitializerError, StackOverflowError or NoClassDefFoundError. Understand which of these are thrown by the virtual machine and recognize situations in which others should be thrown programatically.


So I think one has to know these exceptions. There would be questions which relate to which exception might be thrown or to categorize the exceptions as Unchecked/Checked.

 
Janeice DelVecchio
Saloon Keeper
Posts: 1800
12
Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! That is very helpful. And the link is easier to understand than some of the other pages I've looked at about checked vs unchecked....

Do you suppose that the list in the flow control objectives contains the only exceptions that need to be memorized?

EDIT.... those are all unchecked or errors. Is there a list of checked exceptions to memorize?
 
Mohamed Sanaulla
Saloon Keeper
Pie
Posts: 3159
33
Google App Engine Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Janeice DelVecchio wrote:
Do you suppose that the list in the flow control objectives contains the only exceptions that need to be memorized?


I think that's it to be known from the point of exam. And also Flow Control mentions other topics related to Exceptions. But the list of Exceptions they have provided are often encountered in the other objectives being covered like-NumberFormatException in parsing String to int(or other type), IllegalStateException in Threads(?) . If you consider Exceptions related to SQL/JDBC, as SQL/JDBC are not part of the SCJP objectives. Also you should be aware of any Exceptions which are mentioned in the other objectives- like the File IO related excpetions.

Edit: Checked exceptions come under the different objectives- so any API part of the objective and it throws some error- One has to know about it But what ever mentioned in the K&B guide is more than enough. Would like to hear from other Ranchers regarding this. While I was preparing I didnt worry about exceptions not mentioned in the book- either in the Code examples or in the text.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic