Not sure what I am doing wrong here. I have a tiny program setup to parse requests on my localhost. My client has this:
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);
My server code should be able to handle this:
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...
}
}
Server logs this:
// it gets the request, player is null...
Instance of '_HttpRequest@14117cc4'
{player: null}
got player num null
false
false
But then BOOM! -> in dart:bootstrap_impl… around line 1255
int pow(int exponent) {
throw "Bigint.pow not implemented";
}
The main issue I see at the moment is:
In this case, you are checking to see if player_num is a null value. However you don’t check to see if the value is a string ‘null’ which it appears to be in this case.
From this point it should throw a FormatException when you pass it to parseInt (note: Should not be using the Math. static class, as it is a top-level function within dart:math. The static class Math. is still from dart:core).
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.