Issue 8571 - Defined exception for unequal zip lengths with StoppingPolicy.requireSameLength
Summary: Defined exception for unequal zip lengths with StoppingPolicy.requireSameLength
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-21 04:41 UTC by bearophile_hugs
Modified: 2024-12-01 16:15 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2012-08-21 04:41:41 UTC
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.
Comment 1 RazvanN 2017-07-10 13:12:07 UTC
From what I understood, the phobos administrators are pretty reluctant to adding new exceptions unless they are definitely needed.
Comment 2 dlangBugzillaToGithub 2024-12-01 16:15:34 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/9593

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB