Aleana Cologne wrote:Hi everybody,
Maybe someone can enlighten me:)
In OCA Study guid for OCA 8 from Boyarski and Selikoff. In Chapter 6 ( and in Javadoc from Oracle) NumberFormatExceptions are a child class of RunTimeException. this far I understand the Point with checked and unchecked.
But than in the Review Questions of that chapter , Question 5 I am asked which of the following exceptions are thrown by the JVM and
obviously i choosed NumberFormatException as an answer.
But it isn't thrown by JVM as the solution told me but a programmatically thrown one through Wrapper class.
And this is something I don't get right.
Because nearly everywhere I was told Runtime Exception are thrown by JVM ..
I marked this as something like a rule to remember , but now ;( …
Is there someone to explain that to me ? Or is it just a Special kind of rule I have to remember , and if yes,are there some more specialties coming with that topic ?
Thanks for helping me out
Alex
Mike Simmons wrote:There are many, many cases where these can be thrown programmatically as well. Even specific exceptions that are thrown by the JVM, like NullPointerException or ClassCastException, may be thrown programmatically as well, if someone feels like writing code that does that.
So, you can learn specific situations where the JVM will throw a RuntimeException, or an Error. But never assume that's the only way that RuntimeException or Error can be thrown.
Thus, the "only" rule is thatThey can be thrown by the programmer or by the JVM.
They don't have to be handled or declared.
Aleana Cologne wrote:Hi @ all
Thank you so much for helping me out with that Topic and I got the Point now
RuntimeException is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtual Machine.
Campbell Ritchie wrote:How are you supposed to know that the wrapper class throws such exceptions? Does it say anything in the book or the documentation that the method throws its own exceptions?
Gp and look through your Java® installation folder; there is a file called src.zip in there (at least there often is). Unzip that file and go to the .../java.base/java/lang/Integer.java file, and in the code for the parseInt(String, int) method, you will find all sorts of lines like this:-That confirms what CO'L told you about how such exceptions are thrown, but how would you know without looking at the source?
Often the most important part of the news is what they didn't tell.
no wonder he is so sad, he hasn't seen this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|