aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception being thrown by JVM / Programmatically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception being thrown by JVM / Programmatically" Watch "Exception being thrown by JVM / Programmatically" New topic
Author

Exception being thrown by JVM / Programmatically

Anbarasu Aladiyan
Ranch Hand

Joined: Jun 02, 2009
Posts: 182

hi all,

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


Regards,
A.A.Anbarasu


A.A.Anbarasu
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

Exceptions which are thrown by JVM inherits from Error class. You needn't to handle them.


SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Anbarasu Aladiyan
Ranch Hand

Joined: Jun 02, 2009
Posts: 182

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

Joined: Apr 20, 2009
Posts: 804
    
    1

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

Joined: Aug 26, 2006
Posts: 4968
    
    1

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

Joined: Apr 24, 2009
Posts: 317
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


SCJP 6 - SCJD - SCWCD 5 - SCBCD 5
JavaEnterpriseEditionFaq - TomcatFaq
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
beautiful explanation by Cameron McKenzie....


scjp 1.6 91%, preparing for scmad
"Time to get MAD now.. we will get even later"....by someone unknown
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

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.


"A problem well stated is a problem half solved.” - Charles F. Kettering
SCJP 6, OCPJWCD
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
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

Joined: Dec 10, 2009
Posts: 521
yup all the jvm exceptions(am not talking about errors here) are unchecked...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception being thrown by JVM / Programmatically