• 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

How to "clean up" exception handling from business logic code?

 
Ranch Hand
Posts: 73
1
Python Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working on a framework/library that simplifies coding for non-experts.
I am basically wrapping up lots of "driver" code as a fluent interface DSL, such as:

However, in my work, I call lots of methods that require exception handling:


The end result is that, while the "user" (in this case, a lightweight developer) expects "neat" code, every method they use from the DSL requires about a dozen of:

Which needs to be imported and "thrown" in each method definition, losing a lot of code readability.

I am pretty happy with my exception handling as it is. It's a nice mix of preventing damage to the data but also allowing some benign problems to carry on, with an
informative warning in the end.

Just wondering how to move it out of the class where people will code using my DSL, keeping it in the more-technical classes.

Any tiny code example or google suggestions appreciated!
 
Todor Kolev
Ranch Hand
Posts: 73
1
Python Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My goal is something like this:



My current situation:



And that still doesn't look as bad as it is in reality!

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you decided how many of those exceptions you need to handle in your code and how many need to be thrown?
Why haven't you created your own exception, so you simply need to decare the supertype exception and you can leave it to users to decide how to handle it?
If your users allow an incorrect argument to pass to your business logic, it will need correcting, so you will need some sort of exception for them to catch and correct.
 
Watchya got in that poodle gun? Anything for me? Or this 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