• Post Reply Bookmark Topic Watch Topic
  • New Topic

exception  RSS feed

 
bairava surya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when am practicing mock exams found this question please clarify it?

question:which of them is often thrown by the developer?
answer:numberformatexception


whether numberformatexception is checked or unchecked?
is it possible for developer to throw both checked and unchecked?
 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your question makes no sense. You appear to have omitted a large portion of information in your question.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

The Catch or Specify Requirement

After studying this, can you tell us if NumberFormatException is a checked or unchecked exception?
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
… and what did you think was the answer to your third question?
 
Dennis Grimbergen
Ranch Hand
Posts: 159
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bairava surya wrote:
question:which of them is often thrown by the developer?
answer:numberformatexception

I think you mean it is caught by the developer, not thrown?

The answers to your other two questions should be rather simple to find.
 
bairava surya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the exact question!my doubt is all the exceptions can be thrown by the developers why only these options are correct?
Capture.PNG
[Thumbnail for Capture.PNG]
image
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?"
 
bairava surya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there any other exceptions thrown by the developers?
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You must tell us where that question is from, please.

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.
 
bairava surya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which Exceptions do you think a developer would write? You are looking for code like this:-What sort of Exception would you want there?

And thank you for telling us where the question is from.
 
bairava surya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did they show three as the answer, or did you?

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
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
explain me how i can classify the exceptions that are thrown by the developers vs JVM?
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!