Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error Class in java

 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody ,
we know classes that derived from Error represent unusual situations that are not caused by program errors such as JVM running out of memory .

My question is then why Error class is included by Sun ? Is there any specific reason ?

Another thing is : Generally our application won't be able to recover from an Error.

Is this statement is correct ?

If correct then basically RuntimeException and Error are both same .


Please give your comments .

Thanks & regards,
S
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. A RuntimeException and an Error are very different. A RuntimeException is caused by an error (usually incorrect code) occurring entirely inside the runtime environment. An Error may occur outwith the runtime environment, eg running out of memory.
Read the API documentation for Error and RuntimeException and a few of their subclasses. It also means that catch (Exception ex) will allow Errors to propagate.
You should not normally use catch (Error er), but if you ever do, remember to propagate instances of ThreadDeath.
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Campbell Ritchie .

Could you please explain :
Campbell Ritchie wrote:You should not normally use catch (Error er), but if you ever do, remember to propagate instances of ThreadDeath.


regards,
S

 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's in the API documentation for ThreadDeath.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic