构造函数中的语法错误

时间:2013-02-01 11:18:15

标签: dart

以下代码

class MemberException extends ServerException {
  String message;
  MemberException(message) {
    super(message);
  }
}

class ServerException implements Exception {
  String message;
  ServerException(this.message);
}

产生以下(有点无用)错误消息

Too few arguments in implicit super() constructor invocation in '(String) -> dynamic'

1 个答案:

答案 0 :(得分:2)

正确的格式是:

class MemberException extends ServerException {
  String message;
  MemberException(message) : super(message) {
    // constructor body
  }
}

您需要在调用构造函数体之前初始化super。 参考:http://www.dartlang.org/docs/dart-up-and-running/contents/ch02.html#ch02-constructors(参见初始化者的部分)