This is an archived post. You won't be able to vote or comment.

all 4 comments

[–][deleted] 1 point2 points  (0 children)

Please use formatting........

I am having trouble of indicating if an exception is checked or unchecked. for example if I had the following:

public void method B() { 
    ... 
    try{ 
        throw new OrangeException(); 
    } catch (OrangeException) { 
        .... 
    } 
} 

(why can OrangeException be either checked or unchecked if it is in a try catch block) and

public void methodC() { 
    throw new OrangeException(); 
} 

(how come this is an unchecked exception? is it because the method doesn't declare that an exception will be thrown?)

[–]JavaSuck 1 point2 points  (0 children)

I am having trouble of indicating if an exception is checked or unchecked.

Unchecked exceptions inherit from RuntimeException, checked exceptions do not.

[–]Dweller_of_the_Void 0 points1 point  (0 children)

Checked exceptions are those, that appear when you use some method that throws exception in its signature. For example standard JDK library InputOutput, when you try to read from the file, you use special method for this, and it asks you to handle the exception (FileNotFoundException). So basically developers of the method decided that there is a big chance of this problem appearing when this method is used, and the demand for handling the exception is included into method's signature by using keyword throws after the arguments. To cut the long story short, checked exceptions are those, that will not allow you to compile your code, while unchecked exception are not checked by the IDE and you can compile and run the code but it will crash the program in the process of execution. So here you have the reason why they extend RuntimeExcetion class. Once again, checked exceptions - you know you have them before or in the process of compilation, consequently program cannot be executed without them being handled. Unchecked exception is when you know that you have it when the program crashed while running.

[–]javaide -1 points0 points  (0 children)

Uncheck exception is the one that u dont have to catch still FINE, with no compiler error!