Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
@KieranP

Description

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.

get(key: K): V {
let entry = this.find(key, HASH<K>(key));
if (!entry) throw new Error(E_KEYNOTFOUND); // cannot represent `undefined`
return entry.value;
}

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /