• Post Reply Bookmark Topic Watch Topic
  • New Topic

catch (Throwable) VS catch (Exception)  RSS feed

 
Sharon whipple
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can somone please tell me what is the difference between :


Thank you!!

Sharon
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you catch Throwables, you will also catch Errors. Most often, that's not what you want.
 
Sharon whipple
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Ilja
Sorry for my ignorance, but what do you mean by "you will also catch Errors"

Thank you
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the javadocs for java.lang.Throwable .
Error and Exception extend Throwable.
Look at them.
See what is derived from Error and from Exception.

As a rule of thumb: Catch the specific exception, you expect - not generally anything.
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look up Throwable and Error and Exception in the API.
There was discussion about Exceptions on this thread recently. Find the references to ztor and, more usefully, the Java Tutorial about Exceptions.

See if those help to work out the difference between Throwable Error and Exception.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!