Re: TryElseExpression DIP

2016-09-05 Thread Basile B. via Digitalmars-d
On Monday, 5 September 2016 at 20:04:43 UTC, pineapple wrote: On Monday, 5 September 2016 at 19:12:02 UTC, Jacob Carlborg wrote: [...] On 2016-09-05 20:57, pineapple wrote: Which is easier to read and to write? Which is more maintainable? Which is less prone to programmer errors? This?

Re: TryElseExpression DIP

2016-09-05 Thread pineapple via Digitalmars-d
On Monday, 5 September 2016 at 19:12:02 UTC, Jacob Carlborg wrote: On 2016-09-05 20:57, pineapple wrote: In this case, the catch block will catch both errors from do_a_thing and depends_on_success_of_thing. Then move it to after the "finally" block. It would actually have to be inside the

Re: TryElseExpression DIP

2016-09-05 Thread Jacob Carlborg via Digitalmars-d
On 2016-09-05 20:57, pineapple wrote: In this case, the catch block will catch both errors from do_a_thing and depends_on_success_of_thing. Then move it to after the "finally" block. -- /Jacob Carlborg

Re: TryElseExpression DIP

2016-09-05 Thread pineapple via Digitalmars-d
On Monday, 5 September 2016 at 18:27:44 UTC, ag0aep6g wrote: Can you point out how this is different from (and better than) try { do_a_thing(); depends_on_success_of_thing(); } catch (...) { ... } finally { ... } ? On Monday, 5 September 2016 at 18:27:52 UTC, arturg wrote: hm,

Re: TryElseExpression DIP

2016-09-05 Thread ag0aep6g via Digitalmars-d
On 09/05/2016 08:07 PM, pineapple wrote: try{ do_a_thing(); }catch(Exception exception){ handle_error(); }else{ depends_on_success_of_thing(); }finally{ do_this_always(); } Would be equivalent to bool success = false; try{

Re: TryElseExpression DIP

2016-09-05 Thread arturg via Digitalmars-d
On Monday, 5 September 2016 at 18:07:52 UTC, pineapple wrote: It works like this: try: do_something() except Exception as e: pass # Runs when an error inheriting from Exception was raised else: pass # Runs when no error was raised finally: pass

TryElseExpression DIP

2016-09-05 Thread pineapple via Digitalmars-d
I was writing some code and realized D doesn't have an equivalent to Python's `else` for error handling, and I think we should change that https://github.com/dlang/DIPs/pull/43/files In Python, the try/catch/finally syntax is augmented with an additional clause, termed else. It is a