You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
catch syntax is confusing (looks like an annotation) #2948
Types are both used as annotations (don't affect behaviour) and as references (do affect behaviour), in different contexts:
Annotations:
T local = 42;
T method() { }
method(T param);
References:
new T();
x is T
List<T>
extends T
catch (T foo)
Note that catch syntax fits the pattern of an annotation, but it's actually a behaviour-affecting reference to the type!
This confuses people (myself, and others on the mailing list).
The catch syntax originates with languages that don't have this inconsistency, because types are enforced rather than annotations. In these languages, the most similar syntactic construct (method parameter declarations) is used for a pattern matching construct (overloading) similar to catch. This similarity is not present in Dart, so the similar syntax is misleading.
I think the following syntax is an improvement:
} catch (x is T) {
Pros:
* syntax is already reserved
* type appears at the end of the expression, like other type references
* meaning is obvious
Cons:
* looks like a boolean expression
* less familiar than current syntax to Java/C++/C# developers
There's probably even better syntax to be found, though.
Activity
anders-sandholm commentedon May 9, 2012
Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.
gbracha commentedon May 9, 2012
I agree the use of types in the catch syntax is at odds with the rest of the language.
Set owner to @gbracha.
Added Accepted label.
gbracha commentedon May 29, 2012
Added this to the M1 milestone.
gbracha commentedon Jun 19, 2012
The next rev of the spec (0.11) updates the catch syntax to resolve this issue and make it cleaner.
Added Done label.
gbracha commentedon Jun 20, 2012
Analyzer issue #3576
VM issue #3577
dart2js issue #3578
sethladd commentedon Jun 20, 2012
News post for this update: http://news.dartlang.org/2012/06/darts-catch-syntax-revisited.html
DartBot commentedon Aug 8, 2012
This comment was originally written by @mhausner
Gilad, the spec does not say whether "on" is a reserved word or a built-in identifier. Please update the spec accordingly.
Added NeedsInfo label.
gbracha commentedon Aug 8, 2012
That is because it is neither. The word "on" was deemed too important in web APIs etc.
DartBot commentedon Aug 14, 2012
This comment was originally written by @aam
Correcting links to relevant issues:
Analyzer http://code.google.com/p/dart/issues/detail?id=3756
VM http://code.google.com/p/dart/issues/detail?id=3757
dart2js http://code.google.com/p/dart/issues/detail?id=3758
gbracha commentedon Aug 14, 2012
Added Done label.