• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JVM, programmatic, runtime exceptions

 
Jacky Zhang
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand the following:

JVM exceptions Those exceptions or errors that are either exclusively or most logically thrown by the JVM.
NullPointerException,
StackOverflowError,
ArrayIndexOutOfBoundsException,
ClassCastException,
ExceptionInInitializerError,
NoClassDefFoundError.

Programmatic exceptions Those exceptions that are thrown explicitly by application and/or API programmers.
NumberFormatException,
AssertionError,
IllegalArgumentException,
IllegalStateException.

But then when it says "it�s okay for the overriding method to throw any runtime exceptions." i got the question:

What are runtime exceptions as far as JVM and programmtic exceptions mentioned above is concerned?

Are programmatic exceptions all runtime exceptions? what about JVM exceptions? are they not runtime exceptions?
 
Neelesh Bodas
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by enen:
What are runtime exceptions as far as JVM and programmtic exceptions mentioned above is concerned?


Limiting ourselves only to the 10 Throwables listed above, all the exceptions in the above list are RuntimeExceptions. Note that the list has 4 errors and 6 exceptions.

Also note that all the 10 Throwables in the above list can be thrown fromanywhere without declaring or handling them.
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi enen,

We'd like you to change your display name to meet our naming policy!

We've found it keeps the ranch friendlier

Good luck in your studies,


Bert
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And here's the link to the JavaRanch Naming Policy
 
Jacky Zhang
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How many of these are checked exceptions?
How is checked exception defined?
 
Henry Wong
author
Marshal
Pie
Posts: 21416
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jacky Zhang:
How many of these are checked exceptions?
How is checked exception defined?


A runtime exception is an exception that IS-A RuntimeException -- meaning an object that is either that class type or subclass of that type.

The significance of the RuntimeException class is that the compiler will not require you to declare that you throw that exception, or require you to catch it. It is basically an "unchecked" exception.

A "checked" exception is an exception that is not an "unchecked" exception -- or an exception that is not a RuntimeException.


[EDIT: new text below]

Just realize that this thread also refers to errors.

An Error is a throwable object that IS-A Error -- meaning an object that is either that class type or subclass of that type.

Like runtime exceptions, it is also unchecked. However, it is separated from runtime exceptions because it is *not* recommended that you catch these, as they generally indicate an abnormal condition that may not be recoverable.

Henry
[ September 20, 2006: Message edited by: Henry Wong ]
 
Tom Johnson
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jacky,
"Are programmatic exceptions all runtime exceptions?"
It depends :
There is an actual class called RuntimeException. If a particular exception entends this, then it is a runtime exception. Examples include ArrayIndexOutOfBoundsException & NullPointerException. There are not checked exceptions in that they dont need to be declared as a possible exception that could be thrown from a method. Similarly the dont need to be handled by the calling method with an explicit catch or declare.

"what about JVM exceptions? are they not runtime exceptions?"
Some of them are - ArrayIndexOutOfBoundsException, NullPointerException as mentioned. However, StackOverflowError is an error, not an exception. Errors are far more serious and shouldnt really be handled by application.

Anyway - StackOverflowError, what could you do?!!

Tom
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic