不确定我在这里做错了什么。我有一个小程序设置来解析我的本地主机上的请求。我的客户有这个:
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
然后是BOOM! - >在dart:bootstrap_impl ...在第1255行附近
int pow(int exponent) {
throw "Bigint.pow not implemented";
}
答案 0 :(得分:1)
我目前看到的主要问题是:
if (player_num == null) {
在这种情况下,您正在检查player_num是否为空值。但是,您不检查该值是否为字符串'null',在这种情况下它似乎是。
从这一点开始,当你将它传递给parseInt时它应该抛出一个FormatException(注意:不应该使用Math。静态类,因为它是dart中的顶级函数:math。静态类Math。仍然是来自dart:core)。
话虽如此,我的try / catch使用了parseInt('null');确实抓住了这个错误。令我困惑的是,你的错误表明正在显示的错误是'pow()'函数,而且与parseInt()根本没有关系。