Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Confusion regarding exceptions thrown by Developer or by JVM

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I'm a little bit confused about following:

Which is NOT thrown by JVM, but instead thrown by the developer?

1. StackOverflowError
2. NullPointerException
3. NumberFormatException
4. NoClassDefFoundError
5. ArrayIndexOutOfBoundsException

And the correct answer is (3) NumberFormatException. I couldn't understand what does it mean thrown by developer and not JVM, how should we differenciate them? Actually I thought that NullPointerException and ArrayIndexOutOfBoundsException are also thrown by developer, as they are unchecked exceptions.

Any suggestions are welcome.
Thanks
 
Ranch Hand
Posts: 101
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The NumberFormatException can be thrown by a programmer e.g. to inform that a method has a wrong argument. Rest of errors and exceptions are thrown to inform that something went wrong.
1. StackOverflowError - out of amemory
2. NullPointerException - null reference
4. NoClassDefFoundError - class not found
5. ArrayIndexOutOfBoundsException - wrong index
 
Mary Hansen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But the same way NullPointerException was thrown because the developer tried for example to call a method on a null reference object?
 
Mark Moge
Ranch Hand
Posts: 101
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mariam Hhh wrote:But the same way NullPointerException was thrown because the developer tried for example to call a method on a null reference object?


In this case the exception is thrown by JVM. Exception is thrown by programmer if he/she writes explicitly
 
Mary Hansen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyway I cannot get the point 100%, how the differentiation is done. The same way ClassCastException I thought is thrown by developer, because developer converts an object from one type to another.
I would be very thankful if you could refer me to some link or article, where actually I can read the reason and explanation for this.

Thanks in advance.
 
Sheriff
Posts: 9674
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mariam please check your private messages for some administrative matter.

Also see if this exception types article helps...
 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Look at Errors as something from which you cannot recover & the JVM decides.

StackOverFlow - no way to proceed because you cannot call any more methods
OutOfMemory - again no way to proceed
NoClassDef - this is a again a runtime requirement which is not exactly in the developers basket
He can use all dependancies during compilation, but during execution - the environment must contain the dependancies

Look at unchecked exception as something you can prevent by using proper code logic

NullPointer - you can always do a null check to prevent it
Index exception - You can always check the length/size before any operations
Number Format - You can always validate input through any mechanisms (Regex, Validation tools in your framework).

IN short these runtime or unchecked exceptions can be avoided by properly coding you program.

But Exceptions like FileNotFound etc which are checked exception can occur due
parameters outside the control of the developer.

You can have better idea if you read more about exceptions & errors.

Kindly follow the link suggested by Ankit & books/links suggested on the forums.

Hope this leads you to a clearer path on exceptions.
 
Mary Hansen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

Actually I understand the concept of checked and unchecked exceptions very clearly. And I'm very familiar with all the mentioned Exceptions and its usages.
The problem was that in SCJP mock exam I encountered a question, which was asking whether the exception is thrown by the Developer or by JVM, and haven't thought that actually "thrown by developer" in the question means "unchecked exceptions", which for sure are thrown because of program bugs. Many thanks to all of you for the clarification.
 
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic