assemblyscript icon indicating copy to clipboard operation
assemblyscript copied to clipboard

Map.get() always returns error, no way to catch it?

Open KieranP opened this issue 1 month ago • 6 comments

Question

I'm writing an AssemblyScript version of Conways Game of Life - https://github.com/KieranP/Game-Of-Life-Implementations

Part of it needs to fetch values from a Map but the key may not be there.

private cell_at(x: u32, y: u32): Cell {
  return this.cells.get(`${x}-${y}`)
}

However, AssemblyScript always throws an error instead of returning null.

https://github.com/AssemblyScript/assemblyscript/blob/8257b1c60b6dc9a6a1395236b95a82efc261e3b8/std/assembly/map.ts#L103-L107

Map.find() is a private method, so I can't use that. And trying to use try/catch throws error ERROR AS100: Not implemented: Exceptions.

So how am I supposed to do this, try and fetch a map value, and handle when the map doesn't have the expected value?

KieranP avatar Oct 27 '25 03:10 KieranP