File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Difference between Exception and Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difference between Exception and Error" Watch "Difference between Exception and Error" New topic
Author

Difference between Exception and Error

Zubair Mushtaq
Greenhorn

Joined: Sep 06, 2003
Posts: 10
i have confusion about exception and error.suppose if u make a software so u must b having Exception handling in that.so wat ab errors?can they b handled like exceptions? if yes then what is the differece between both of these?
Jon Strayer
Ranch Hand

Joined: Dec 04, 2002
Posts: 133
You have to declare Exceptions you may throw in your throws clause. You don't have to do this with Errors. Other than that, they are identical.


Jon
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
You have to be a bit more specific about what you mean by "error". Notice that Error is a Java class, too, in the following hierarchy:

Throwable <-- Error <-- ...
Throwable <-- Exception <-- ...
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
In a perfect world, and in a nutshell...
Errors represent problems that aren't typically handled by a program. They represent severely bad situations that should not occur, and that a programmer should not try to recover from.
Sometimes errors occur because of (external) conditions that cannot be controlled or effected by the running Java program.
Exceptions come in too basic forms: Runtime Exceptions (aka Unchecked Exceptions) and Checked Exceptions.
Runtime Exceptions typically are not meant to be handled by a program. They often represent programmer errors, that should reveal themselves at run time and that should be fixed by the programmer correcting the code problem.
Checked Exceptions typically represent problem conditions outside of a program's control, but should be recovered from by the program.
For more information, a good place to learn lots of different and good ideas on exceptions in Java is at http://c2.com/cgi/wiki?JavaExceptionHandling
Does that help?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Thanks for that link - some solid discussion about exception issues. This is a controversial area and I was surprised to see almost nothing newer than 2000, tho.
Did anybody see the Throws Excepiton By Default page? I think I'm for it. I've been doing a lot of stuff that reads streams lately, and letting any exceptions percolate quite a way up the stack to a higher level class for any handling.


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 Exception and Error