• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between Exception and Error

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 <-- ...

 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic