• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception being thrown by JVM / Programmatically

 
Anbarasu Aladiyan
Ranch Hand
Posts: 182
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

I need some help. What is the difference between a Exception thrown by JVM and thrown Programmatically?


Regards,
A.A.Anbarasu
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exceptions which are thrown by JVM inherits from Error class. You needn't to handle them.
 
Anbarasu Aladiyan
Ranch Hand
Posts: 182
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lukas Smith wrote:Exceptions which are thrown by JVM inherits from Error class. You needn't to handle them.


Thats ok. But how do we know an Exception is thrown by JVM?
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We do not know . In some cases we can predict a little (fe. w create a huge array of objects, and we fill that array - JVM can throw an exception because of running out of memory).
If an exception of JVM is thrown - your program will crash - stop working.
How can you predict if tomorrow this time there will be raining?
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're driving somewhere, and you have bad directions, you won't get there, because the directions are faulty. That's really your fault, because you've taken directions that were faulty. That's like an Exception caused by programming. If you don't arrive where you're going because of bad directions, that's not the car's fault.

On the other hand, your car might break down, or blow up, or a tire may blow, and you can't get to where you're going. That's really an error with the car, not the directions you've been given. In the Java world, that would be like a JVM error - the JVM error just sorta blew up doing what it's supposed to do.

Both stop you from getting to where you're going, but one has more to do with the programmer(driver), while the other had more to do with the car itself (the JVM).

-Cameron McKenzie
 
Bob Wheeler
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lukas Smith wrote:Exceptions which are thrown by JVM inherits from Error class. You needn't to handle them.

There are no exceptions inherited from the Error class. ALL exceptions are inherited by the Exception class; checked and unchecked
(subclasses from RuntimeException). But there is at least one Error class which are regarded as thrown by the JVM (AssertionError).

cheers
Bob
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
beautiful explanation by Cameron McKenzie....
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bob Wheeler wrote:
Lukas Smith wrote:Exceptions which are thrown by JVM inherits from Error class. You needn't to handle them.

There are no exceptions inherited from the Error class. ALL exceptions are inherited by the Exception class; checked and unchecked (subclasses from RuntimeException). But there is at least one Error class which are regarded as thrown by the JVM (AssertionError).

All the exceptions which are sub-classes of Error class are thrown by JVM. There are also exceptions which are sub-classes of Exception class (actually they are sub-classes of RuntimeException to be more specific) which are thrown by the JVM. All the JVM exceptions are unchecked...
 
Nidhi Sar
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Garg wrote:All the exceptions which are sub-classes of Error class are thrown by JVM.


As per K & B book, AssertionError is thrown programmatically, not by JVM. Is that incorrect?

Ankit Garg wrote:All the JVM exceptions are unchecked...


But the reverse is not true, right? IllegalArgumentException, IllegalStateException & NumberFormatException are all unchecked exceptions, but they are thrown programmatically, not by JVM.
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AssertionError is thrown progammatically and not by jvm....i think other than that all the errors are thrwn by the jvm..actually you dont have know about other errors except assertionerror
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup all the jvm exceptions(am not talking about errors here) are unchecked...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic