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

Cannot use '=>' syntax for declaring function to throw an exception #3370

Closed
DartBot opened this issue Jun 3, 2012 · 4 comments
Closed

Cannot use '=>' syntax for declaring function to throw an exception #3370

DartBot opened this issue Jun 3, 2012 · 4 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report

Comments

@DartBot
Copy link

DartBot commented Jun 3, 2012

This issue was originally filed by ren...@gmail.com


What steps will reproduce the problem?

Object thrower(String msg) => throw new UnsupportedOperationException(msg);

What is the expected output? What do you see instead?

Defining the same function with curly braces works, but I don't see why I can't use the short form:

Error: line 1 pos 31: unexpected token 'throw'
Object thrower(String msg) => throw new UnsupportedOperationException(msg);

What version of the product are you using? On what operating system?

Dart SDK version 7904

@DartBot
Copy link
Author

DartBot commented Jun 3, 2012

This comment was originally written by ladicek@gmail.com


Note that '=> ...' is a syntactic shortcut for '{ return ... }'. Here, that would mean

Object thrower(String msg) {
  return throw new UnsupportedOperationException(msg);
}

In Dart, not everything is an expression (that returns value), there are also statements. Throw is one of those. I agree that it is inconvenient sometimes, but it makes sense.

@DartBot
Copy link
Author

DartBot commented Jun 3, 2012

This comment was originally written by re...@gmail.com


Ok, I understand.

Still I think the following example is rather surprising.

This works:

   void sayHello() => print("Hello");

This doesn't work:
   
   void throwHello() => throw new UnsupportedOperationException("Hello");

Sorry for the short issue-summary, I intended to write a better one but cannot edit it anymore.

@madsager
Copy link
Contributor

madsager commented Jun 4, 2012

Added Area-Language, Triaged labels.
Changed the title to: "Cannot use '=>' syntax for declaring function to throw an exception".

@rakudrama
Copy link
Member

Added Duplicate label.
Marked as being merged into #587.

@DartBot DartBot added Type-Defect area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report labels Jun 4, 2012
copybara-service bot pushed a commit that referenced this issue Apr 5, 2022
Changes:
```
> git log --format="%C(auto) %h %s" a3a102a..a949b32
 https://dart.googlesource.com/pub.git/+/a949b329 Fix handling of 'git@github.com:dart-lang/pub.git' style urls in git source (#3381)
 https://dart.googlesource.com/pub.git/+/c6cd3758 Always use forward slash for relative paths in lockfile (#3379)
 https://dart.googlesource.com/pub.git/+/7d48f902 Remove unused function (#3370)
 https://dart.googlesource.com/pub.git/+/b1373d4c Fix import prefix (#3369)

```

Diff: https://dart.googlesource.com/pub.git/+/a3a102a549388a6dbfecc9252fabb618f9a2f5f7~..a949b329b1b51f5f3973a790e0a0a45897d837de/

A bunch of bugfixes.

Change-Id: I1f791cad27194359091f489f36dcc3ad2b78bb31
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240052
Reviewed-by: Jonas Jensen <jonasfj@google.com>
Commit-Queue: Sigurd Meldgaard <sigurdm@google.com>
copybara-service bot pushed a commit that referenced this issue Apr 25, 2022
Changes:
```
> git log --format="%C(auto) %h %s" a3a102a..a949b32
 https://dart.googlesource.com/pub.git/+/a949b329 Fix handling of 'git@github.com:dart-lang/pub.git' style urls in git source (#3381)
 https://dart.googlesource.com/pub.git/+/c6cd3758 Always use forward slash for relative paths in lockfile (#3379)
 https://dart.googlesource.com/pub.git/+/7d48f902 Remove unused function (#3370)
 https://dart.googlesource.com/pub.git/+/b1373d4c Fix import prefix (#3369)

```

Diff: https://dart.googlesource.com/pub.git/+/a3a102a549388a6dbfecc9252fabb618f9a2f5f7~..a949b329b1b51f5f3973a790e0a0a45897d837de/

A bunch of bugfixes.

Change-Id: I1f791cad27194359091f489f36dcc3ad2b78bb31
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240052
Reviewed-by: Jonas Jensen <jonasfj@google.com>
Commit-Queue: Sigurd Meldgaard <sigurdm@google.com>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report
Projects
None yet
Development

No branches or pull requests

3 participants