• 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

Seriously Good Software: Catching exceptions

 
Ranch Hand
Posts: 144
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I saw this pop quiz:  What’s wrong with throwing a checked exception as a penalty?. It brought a different question to my mind.
What's wrong about catching/handling exceptions and not allowing it to propagate?
What do you think? Should we always allow exception to propagate?
Do you give any advice in your book about this?

Thanks.
 
Author
Posts: 11
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exceptions should be caught at the level where the appropriate corrective action can be taken.

Corollary: an exception should never be caught by the method that threw it. If it threw it, by definition it doesn't know how to fix it.

If no corrective action is possible, catch it at the level when such impossibility can be ascertained (probably close to your "main" or entry point)
and log it and/or inform the user, as appropriate, before exiting.

In the book I work a lot with exceptions in chapter 5 in the context of reliability,
focusing on when, why, and what type of exceptions to throw.

Marco
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good question.

Jorge Ruiz-Aquino wrote:. . . Should we always allow exception to propagate?  . . .

No. Most of the time there is something you can do to deal with the exception, and as MF has told you, work out where you can best correct the problem.
 
Jorge Ruiz-Aquino
Ranch Hand
Posts: 144
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those are great advises.
Thank you Marco Faella and Campbell Ritchie.
 
crispy bacon. crispy tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic