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 # Runs unconditionally, evaluates last

Imitating this functionality in D,

    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();
        }
    }

hm, isn't this similar/same as the python version?

  try{
      doSomething();

      scope(success) "if no Exception thrown".writeln;
  }
  catch(Exception e)
  {
       ...
  }

Reply via email to