Re: try & catch / repeating code - DRY

2018-05-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, May 24, 2018 19:39:07 Jacob Carlborg via Digitalmars-d-learn wrote: > On 2018-05-24 08:05, Robert M. Münch wrote: > > Hi, great! Thanks for the examples... BTW: Is there a place where such > > generic and fundamental examples are collected? > > Not as far as I know. > > >> void

Re: try & catch / repeating code - DRY

2018-05-24 Thread Jacob Carlborg via Digitalmars-d-learn
On 2018-05-24 08:05, Robert M. Münch wrote: Hi, great! Thanks for the examples... BTW: Is there a place where such generic and fundamental examples are collected? Not as far as I know. void handleException1(alias dg)() { try dg(); catch (Exception e) { /* handle exception */ } }

Re: try & catch / repeating code - DRY

2018-05-24 Thread Robert M. Münch via Digitalmars-d-learn
On 2018-05-22 18:33:06 +, Jacob Carlborg said: You can always create a function that takes a delegate or lambda and handles the exception in the function. Here are three versions of the same thing, depending on how you want the call site to look like. Hi, great! Thanks for the

Re: try & catch / repeating code - DRY

2018-05-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, May 23, 2018 04:07:25 Ali Çehreli via Digitalmars-d-learn wrote: > On 05/23/2018 12:47 AM, Robert M. Münch wrote: > > On 2018-05-22 18:34:34 +, Ali ‡ehreli said: > >> An idiom known in C++ circles is a Lippincott function: > >> > >> > >>

Re: try & catch / repeating code - DRY

2018-05-23 Thread Ali Çehreli via Digitalmars-d-learn
On 05/23/2018 12:47 AM, Robert M. Münch wrote: On 2018-05-22 18:34:34 +, Ali ‡ehreli said: 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

Re: try & catch / repeating code - DRY

2018-05-23 Thread Robert M. Münch via Digitalmars-d-learn
On 2018-05-22 18:34:34 +, Ali ‡ehreli said: 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. Thanks, and I assume that D has the same

Re: try & catch / repeating code - DRY

2018-05-22 Thread Meta via Digitalmars-d-learn
On Tuesday, 22 May 2018 at 18:20:43 UTC, 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.

Re: try & catch / repeating code - DRY

2018-05-22 Thread Ali Çehreli via Digitalmars-d-learn
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

Re: try & catch / repeating code - DRY

2018-05-22 Thread Jacob Carlborg via Digitalmars-d-learn
On 2018-05-22 20:20, 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

try & catch / repeating code - DRY

2018-05-22 Thread Robert M. Münch via Digitalmars-d-learn
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