aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exceptions -- checked versus unchecked.... and which ones are which Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exceptions -- checked versus unchecked.... and which ones are which" Watch "Exceptions -- checked versus unchecked.... and which ones are which" New topic
Author

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

Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1686
    
  12

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?


When you do things right, people won't be sure you've done anything at all.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

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.


Mohamed Sanaulla | My Blog
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1686
    
  12

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

Joined: Sep 08, 2007
Posts: 3071
    
  33

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exceptions -- checked versus unchecked.... and which ones are which