Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defined exception for unequal zip lengths with StoppingPolicy.requireSameLength #9593

Open
dlangBugzillaToGithub opened this issue Aug 21, 2012 · 1 comment

Comments

@dlangBugzillaToGithub
Copy link

bearophile_hugs reported this on 2012-08-21T04:41:41Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=8571

CC List

  • monarchdodra
  • razvan.nitu1305

Description

This is part of Zip.empty() of Phobos:


@property bool empty()
{
    final switch (stoppingPolicy)
    {
...
    case StoppingPolicy.requireSameLength:
        foreach (i, Unused; R[1 .. $])
        {
            enforce(ranges[0].empty ==
                    ranges.field[i + 1].empty,
                    "Inequal-length ranges passed to Zip");
        }
        return ranges[0].empty;
    }


I suggest to replace that enforce() with a throw of a definite exception, named like ZipUnequals or something like that, that allows for a clean catch: catching the enforce() exception is easy, but you can't be sure you are catching that specific zip enforce instead of another one or a bug.

Knowing that a zip(StoppingPolicy.requireSameLength, ...) has thrown an exception for unequal lengths is sometimes useful. When you want to use the zip results and you want to make sure they are equal in length, you want to catch just that specific length problem.
@dlangBugzillaToGithub
Copy link
Author

razvan.nitu1305 commented on 2017-07-10T13:12:07Z

From what I understood, the phobos administrators are pretty reluctant to adding new exceptions unless they are definitely needed.

@LightBender LightBender removed the P4 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants