Skip to content

Can't rethrow in switch expression #3097

Open
@rubenferreira97

Description

@rubenferreira97

Shouldn't be possible to rethrow in a switch expression since we can throw e?
Random example:

void main() {
  try {
    // some code that might throw
  } catch (e) {
    return switch (e) {
        Exception() => print('Return what this function asks for (void).'),
        Error() => throw e, //Works, but warning "Use 'rethrow' to rethrow a caught exception."
        _ => rethrow, // Error "Undefined name 'rethrow'"
    };
  }
}

Inside a catch clause I think we could allow a rethrow statement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureProposed language feature that solves one or more problemsrequestRequests to resolve a particular developer problemsmall-featureA small feature which is relatively cheap to implement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions