-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Cannot use '=>' syntax for declaring function to throw an exception #3370
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
Comments
This comment was originally written by [email protected] Note that '=> ...' is a syntactic shortcut for '{ return ... }'. Here, that would mean Object thrower(String 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. |
This comment was originally written by [email protected] Ok, I understand. Still I think the following example is rather surprising. This works: void sayHello() => print("Hello"); This doesn't work: Sorry for the short issue-summary, I intended to write a better one but cannot edit it anymore. |
Added Area-Language, Triaged labels. |
Changes: ``` > git log --format="%C(auto) %h %s" a3a102a..a949b32 https://dart.googlesource.com/pub.git/+/a949b329 Fix handling of '[email protected]: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 <[email protected]> Commit-Queue: Sigurd Meldgaard <[email protected]>
Changes: ``` > git log --format="%C(auto) %h %s" a3a102a..a949b32 https://dart.googlesource.com/pub.git/+/a949b329 Fix handling of '[email protected]: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 <[email protected]> Commit-Queue: Sigurd Meldgaard <[email protected]>
This issue was originally filed by [email protected]
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
The text was updated successfully, but these errors were encountered: