1

不知道我在这里做错了什么。我有一个小程序设置来解析我的本地主机上的请求。我的客户有这个:

var local_num = null; // init to null
// my server is running on localhost at the moment
// using XMLHttpRequest I send it the value (it woud still be null)
request.open('GET', 'http://127.0.0.1:8080?player=${local_num}', false);

我的服务器代码应该能够处理这个:

action = params['action'];
var player_num = params['player'];
print ("got player num ${player_num}");
print(player_num is num); // false in both cases (see log below)
print(player_num is int);

if (player_num == null) { // never reaches inside of this if clause
print("received num is null, skipping parsing");
} else {
  try {
    var actual_number = Math.parseInt(received_num);
    print("parsed"); // never gets here
  } catch(var e) {
print(e); // should throw...
  }
}

服务器记录此:

// it gets the request, player is null...
Instance of '_HttpRequest@14117cc4'
{player: null}
got player num null
false
false

但随后繁荣!-> 在 dart:bootstrap_impl ... 第 1255 行附近

int pow(int exponent) {
  throw "Bigint.pow not implemented";
}
4

1 回答 1

1

我目前看到的主要问题是:

if (player_num == null) {

在这种情况下,您正在检查 player_num 是否为空值。但是,您不会检查该值是否为字符串“null”,在这种情况下它似乎是。

从这一点开始,当你将它传递给 parseInt 时它应该抛出一个 FormatException (注意:不应该使用 Math.static 类,因为它是 dart:math 中的顶级函数。静态类 Math. 仍然来自 dart:核)。

That being said, my try/catch with a parseInt('null'); does indeed catch the error. What I'm confused by, is that your error is indicating that the error that's being displayed, is for the 'pow()' function and not related to parseInt() at all.

于 2012-08-08T12:36:42.257 回答