try & catch / repeating code - DRY
Ali Çehreli
acehreli at yahoo.com
Tue May 22 18:34:34 UTC 2018
On 05/22/2018 11:20 AM, Robert M. Münch wrote:
> I see that I'm writing
>
> try {
> ... different code ...
> } catch (myException e) {
> ... same handling code ...
> }
>
> over and over again.
>
> Of course I can put the exception handling code into a function to not
> duplicate it. However, I still need to write this construct over and
> over again. Is there a way to handle it more generic? Like:
>
> ??? (... code ...);
>
> or
>
> ??? { ... code ...};
>
> Where ??? would do the try and re-use the exception handling code
> everytime? I hope this is understandable.
>
An idiom known in C++ circles is a Lippincott function:
https://cppsecrets.blogspot.ca/2013/12/using-lippincott-function-for.html
Just wanted to mention that it can be a part of a clean solution.
Ali
More information about the Digitalmars-d-learn
mailing list