• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

difference between JVM thrown exceptions and programmatically thrown exceptions?

 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm not able to understand the difference between two. i know that ArrayIndexOutOfBoundsException is a JVM thrown exception but what if i write in my source code as "throw new ArrayIndexOutOfBoundsException". here i'm throwing ArrayIndexOutOfBoundsException programmatically in my source code. does that make ArrayIndexOutOfBoundsException as programmatically thrown . what is the exact definition ? please explain with an example ?
 
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gurpeet singh wrote:i'm not able to understand the difference between two. i know that ArrayIndexOutOfBoundsException is a JVM thrown exception but what if i write in my source code as "throw new ArrayIndexOutOfBoundsException". here i'm throwing ArrayIndexOutOfBoundsException programmatically in my source code. does that make ArrayIndexOutOfBoundsException as programmatically thrown . what is the exact definition ? please explain with an example ?



As named "programmatically thrown", what are you throwing doesn't mean, matter is that you are throwing.
 
gurpeet singh
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

saloni jhanwar wrote:

gurpeet singh wrote:i'm not able to understand the difference between two. i know that ArrayIndexOutOfBoundsException is a JVM thrown exception but what if i write in my source code as "throw new ArrayIndexOutOfBoundsException". here i'm throwing ArrayIndexOutOfBoundsException programmatically in my source code. does that make ArrayIndexOutOfBoundsException as programmatically thrown . what is the exact definition ? please explain with an example ?



As named "programmatically thrown", what are you throwing doesn't mean, matter is that you are throwing.



so in that case does that mean ArrayIndexOutOfBoundsException is programmatically thrown exception ???
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is a RuntimeException and is expected to be thrown by JVM for runtime failures.
 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gurpeet singh wrote:

saloni jhanwar wrote:

gurpeet singh wrote:i'm not able to understand the difference between two. i know that ArrayIndexOutOfBoundsException is a JVM thrown exception but what if i write in my source code as "throw new ArrayIndexOutOfBoundsException". here i'm throwing ArrayIndexOutOfBoundsException programmatically in my source code. does that make ArrayIndexOutOfBoundsException as programmatically thrown . what is the exact definition ? please explain with an example ?



As named "programmatically thrown", what are you throwing doesn't mean, matter is that you are throwing.



so in that case does that mean ArrayIndexOutOfBoundsException is programmatically thrown exception ???



if you do write code, throw new ArrayIndexOutOfBoundsException(); it means you are explicitly throwing an exception.
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Normally as a programmer, you wouldn't throw a RuntimeException. They are meant to be thrown by the JVM.
 
Ranch Hand
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gurpreet,

What are your definitions for JVM thrown exceptions and Programmatically thrown exceptions?
 
gurpeet singh
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i still dont understand the difference between the two. is it like that all checked exceptions are programmatically thrown exceptions and all unchecked exceptions are JVM thrown ? is it right ?
 
gurpeet singh
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sumit Patil wrote:Gurpreet,

What are your definitions for JVM thrown exceptions and Programmatically thrown exceptions?



im following kb6 book and the kb6 book says :

JVM thrown exceptions are the one that is thrown by JVM logically or explicitly.

Programmaticaly thrown exceptions are the one thrown by the api developers.
 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gurpeet singh wrote:i still dont understand the difference between the two. is it like that all checked exceptions are programmatically thrown exceptions and all unchecked exceptions are JVM thrown ? is it right ?



Using throw keyword you can throw anything error ,checked and unchecked.And when you create your own exception that is also called programmatically.
 
gurpeet singh
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

saloni jhanwar wrote:

gurpeet singh wrote:i still dont understand the difference between the two. is it like that all checked exceptions are programmatically thrown exceptions and all unchecked exceptions are JVM thrown ? is it right ?



Using throw keyword you can throw anything error ,checked and unchecked.And when you create your own exception that is also called programmatically.




so does that mean it all depends upon the context. i.e. normally ArrayIndexOutOfBoundsException is JVM thrown exception but if we explicitly throw it using throw keyword then it is programmatically thrown exception . am i right ? am not able to digest this ? there must be some difference between both of them ?
 
Sumit Patil
Ranch Hand
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would have been better, if you searched the ranch before posting the query

Link
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gurpeet singh wrote:i still dont understand the difference between the two. is it like that all checked exceptions are programmatically thrown exceptions and all unchecked exceptions are JVM thrown ? is it right ?


Nope. As Saloni suggested you could throw any Exception in your program both checked and unchecked. If the API developers chose to throw RuntimeException, then it's a programmatically thrown Exception in that case.

Old threads - thread-1 thread-2
 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gurpeet singh wrote:
so does that mean it all depends upon the context. i.e. normally ArrayIndexOutOfBoundsException is JVM thrown exception but if we explicitly throw it using throw keyword then it is programmatically thrown exception . am i right ? am not able to digest this ? there must be some difference between both of them ?



OK then findout the difference and post here so we also get benefit to know this unrevealed.
 
gurpeet singh
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Jai wrote:

gurpeet singh wrote:i still dont understand the difference between the two. is it like that all checked exceptions are programmatically thrown exceptions and all unchecked exceptions are JVM thrown ? is it right ?


Nope. As Saloni suggested you could throw any Exception in your program both checked and unchecked. If the API developers chose to throw RuntimeException, then it's a programmatically thrown Exception in that case.

Old threads - thread-1 thread-2



thanks john. those links helped a lot.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Jai wrote:Normally as a programmer, you wouldn't throw a RuntimeException. They are meant to be thrown by the JVM.



I sort of disagree. Error and its subclasses are primarily for the JVM, but it's not that uncommon for Java code--including that outside the core API--to throw RuntimeExceptions, or at least a few subclasses. Off the top of my head, I throw IllegalArgumentException and IllegalStateException under various conditions in my code.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gurpeet singh wrote:what is the exact definition ?



I've never heard these terms before. Where did you read them? I would look there for a definition, and, if one is not present, then it seems pretty obvious that "JVM thrown" means those thrown by JVM code, and "programatically thrown" means those thrown by a throw statement in the Java code being executed by the JVM.

These are not standard terms, though.
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gurpeet singh wrote:
so does that mean it all depends upon the context. i.e. normally ArrayIndexOutOfBoundsException is JVM thrown exception but if we explicitly throw it using throw keyword then it is programmatically thrown exception . am i right ? am not able to digest this ? there must be some difference between both of them ?



after reading the definitions from the book YES, i understand it the same as you. but I have never heard these terms before, and am not sure that it really matters.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gurpeet singh wrote:
so does that mean it all depends upon the context. i.e. normally ArrayIndexOutOfBoundsException is JVM thrown exception but if we explicitly throw it using throw keyword then it is programmatically thrown exception



I would say yes.
 
Wendy L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeff Verdegan wrote:

John Jai wrote:Normally as a programmer, you wouldn't throw a RuntimeException. They are meant to be thrown by the JVM.



I sort of disagree. Error and its subclasses are primarily for the JVM, but it's not that uncommon for Java code--including that outside the core API--to throw RuntimeExceptions, or at least a few subclasses. Off the top of my head, I throw IllegalArgumentException and IllegalStateException under various conditions in my code.



a
oh good, I was worrying i was being a naughty girl throwing runtime exceptions. At least I am not alone
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A checked exception is any subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses.

Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. eg, IOException thrown by java.io.FileInputStream's read() method

Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked.

With an unchecked exception, however, the compiler doesn't force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String's charAt() method.

Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be, as they tend to be unrecoverable.

JVM thrown exceptions are runtime /unchecked exceptions-developer doen't know or can not handle those
develper thrown exception are checked exceptions
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeff Verdegan wrote:

John Jai wrote:Normally as a programmer, you wouldn't throw a RuntimeException. They are meant to be thrown by the JVM.



I sort of disagree. Error and its subclasses are primarily for the JVM, but it's not that uncommon for Java code--including that outside the core API--to throw RuntimeExceptions, or at least a few subclasses. Off the top of my head, I throw IllegalArgumentException and IllegalStateException under various conditions in my code.


Thanks Jeff!
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ravi grk wrote:A checked exception is any subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses.

Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. eg, IOException thrown by java.io.FileInputStream's read() method

Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked.

With an unchecked exception, however, the compiler doesn't force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String's charAt() method.

Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be, as they tend to be unrecoverable.

JVM thrown exceptions are runtime /unchecked exceptions-developer doen't know or can not handle those
develper thrown exception are checked exceptions



While this is mostly true, and useful to know, it's not relevant to the question at hand.

Additionally, it appears to be quoted from somewhere. If it is, please QuoteYourSources.(⇐click)
 
Wendy L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ravi grk wrote:A checked exception is any subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses.

Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. eg, IOException thrown by java.io.FileInputStream's read() method

Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked.

With an unchecked exception, however, the compiler doesn't force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String's charAt() method.

Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be, as they tend to be unrecoverable.

JVM thrown exceptions are runtime /unchecked exceptions-developer doen't know or can not handle those
develper thrown exception are checked exceptions


I often catch NumberFormatException and handle it, every time I am checking user input and try converting a string to an integer.

So I still think this the OP's book is making an arbitary and pointless distinction.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Wendy Gibbons wrote:So I still think this the OP's book is making an arbitary and pointless distinction.



Agreed.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Ravi grk", please see your private messages for an important administrative matter.
 
reply
    Bookmark Topic Watch Topic
  • New Topic