Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between Error and Exception

 
Vasu Gunda
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know about Difference between Error and Exception in java
 
S Thanigaivel
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3896
16
Eclipse IDE Flex Google Web Toolkit
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sunny Kumar
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic