Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Difference between Error and Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difference between Error and Exception" Watch "Difference between Error and Exception" New topic
Author

Difference between Error and Exception

Vasu Gunda
Greenhorn

Joined: Dec 17, 2005
Posts: 4
I want to know about Difference between Error and Exception in java
S Thanigaivel
Ranch Hand

Joined: Oct 06, 2005
Posts: 60
Errors and exceptions both inherit from Throwable, but they differ in these ways:

Exceptions:

Can be checked or unchecked
Indicate an error caused by the programmer
Should be handled at the application level

Errors:

Are always unchecked
Usually indicate a system error or a problem with a low-level resource
Should be handled at the system level, if possible
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3716
    
    5

Exceptions are things you can create/throw yourself or that might be thrown because of an obvious run-time error such as trying to access a null object or reading an array out of bounds. They can also be caught and repaired by a developer.

Errors should never be created, thrown, caught, or repaired. They are usually beyond the scope of your application code such as 'out of memory'. Even if you caught an out of memory error, you wouldn't likely be in a better place than the system garbage collector to fix this (and you'd have to fix it while allocating no new memory) so its better to let the system crash and repair the root cause.


My Blog: Down Home Country Coding with Scott Selikoff
Sunny Kumar
Ranch Hand

Joined: Oct 27, 2005
Posts: 57
Exceptions are related to the application and
Error is related to the enviroment in which the application is running.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Even if you caught an out of memory error, you wouldn't likely be in a better place than the system garbage collector to fix this


This is often true but not always. If you just try to allocate an array with Integer.MAX_INT cells it will probably fail. You may well be able to catch the exception and go on your way ... without the array. We had a bug in an EJB app that got out of memory errors while concatenating strings every once in a while. The container caught them and went on running all the other threads just fine. We could have caught them just as well if we wanted.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between Error and Exception