Skip to content

[Bug]: Cannot catch error thrown from nested throwing iterator #27008

@jabraham17

Description

@jabraham17

The following program compiles and runs, but the exception thrown by the second iter these cannot be caught.

record R {
  iter these(start) throws {
    var x = start;
    while true {
      yield x;
      if x == 0 {
        break;
      }
      throw new Error();
      x -= 1;
    }
  }
  iter these() throws {
    for e in this.these(10) do yield e;
  }
}

proc main() {

  var r = new R();

  try {
    for i in r.these(5) {
      writeln(i);
    }
  } catch e {
    writeln("Caught Exception: ", e); // this print works, the exception can be caught
  }

  try {
    for i in r {
      writeln(i);
    }
  } catch e {
    writeln("Caught Exception: ", e); // this print never is called, the exception cannot be caught
  }

}

This program results in the following output

5
Caught Exception: Error: 
10
uncaught Error: 
  bug.chpl:33: thrown here
  bug.chpl:33: uncaught here

This is maybe not that surprising, considering Chapel's limited support for throwing iterators. See #15089, #7134, and #26478

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions