This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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