TryElseExpression DIP

ag0aep6g via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 5 11:27:44 PDT 2016


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{
>         do_a_thing();
>         success = true;
>     }catch(Exception exception){
>         handle_error();
>     }finally{
>         try{
>             if(success){
>                 depends_on_success_of_thing();
>             }
>         }finally{
>             do_this_always();
>         }
>     }

Can you point out how this is different from (and better than)

     try { do_a_thing(); depends_on_success_of_thing(); }
     catch (...) { ... }
     finally { ... }

?


More information about the Digitalmars-d mailing list