• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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: 76861
366
  • 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.
 
Your mother was a hamster and your father was a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic