The following page in Oracle's Java Tutorials explains the three types of exceptions, and how to know whether an exception is a checked exception or not:
Well, yes, the developer can certainly write Java code which throws any of those exceptions. But not all of the options are correct because that isn't the question. Read the question again and you'll find it is significantly different from the question "Which of these exceptions can be thrown by an application developer or an API developer?"
Well, yeah. Have a look at the API documentation. There are hundreds of exceptions which can be thrown by developers. However if you're studying for one of those exams you won't be required to memorize the whole enormous list.
I think your answer to the question asked is incorrect. Part of the technique for success in exams is reading the question correctly. You have answered a different question from what was actually asked (as Paul C has already told you), so I believe you will score −1 on that example.
I got this question from oracle java press exams(cd kathy sierra,bates) please provvide me the correct solution?provide me some useful link to know about the exceptions thrown by the developers?
just my placing the XYZ exception in the catch block we can handle the exception?As an developer we can throw all the exceptions (checked or unchecked)but in the above question why they opted only three?
bairava surya wrote:just my placing the XYZ exception in the catch block we can handle the exception?As an developer we can throw all the exceptions (checked or unchecked)but in the above question why they opted only three?
Because the question asked "which are most commonly thrown by a dev", and not "which can be thrown by a dev".
As you say, a dev could write code to throw any of those, but that doesn't mean they are the sort of exceptions they should be throwing.
The question does not ask anything about catching Exceptions, only about throwing them. You would never throw an Exception and catch it in the same method. That is simply an inefficient way to wrote an if‑else.
bairava surya wrote:explain me how i can classify the exceptions that are thrown by the developers vs JVM?
I don't know that you can. There are no specific rules to say a particular classification of exception can only be thrown by the JVM or by a developer.
Having said that it is often the case (but certainly not always) that Errors will be thrown the JVM and checked exceptions will be thrown by a developer. Other Exceptions such as Runtime exceptions can be thrown by either the JVM or Developer.
You don't have to know how to classify exceptions which are typically thrown by the JVM versus those that developers would typically throw. You only have to know how to put an exception into one of those two categories when you're given its name.
And you have only five names given to you there. So instead of looking for some grand organizing principle you should just ask yourself when each of those exceptions might occur.
If you don't mind my saying so, it seems to me that you are approaching the task of learning Java in the wrong way. It seems to me that you have the idea that there is a big list of things that you have to memorize to pass an exam, and that once you have passed that exam then you will be a Java programmer. But that's not the case. For example in the question you posted, it was written because a Java programmer should know what a ClassCastException is for, and based on that knowledge should be able to answer that question.
Post by:autobot
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
a bit of art, as a gift, the permaculture playing cards