try and except. Instead, operations that can fail return a Lookup. This includes find on a dict or list, and any function you write that can fail.
A Lookup[uint256] is a lookup that holds a uint256 value when it succeeds.
The other ways to read a value (
hello[key] and hello.get(...)) are described in Lists and dicts.Methods
The reason of a missing key names the dict and the key, for example
key 'base' not found in 'hello'.
Handling an error
Usedefault to set a fallback value:
if:
ok() directly and the lookup is an error, the program crashes:
Returning a Lookup
A function can return aLookup. Use Ok(value) for success and Err(reason) for failure.
A Lookup is not its value
You cannot use aLookup where a value is expected. The compiler rejects it and tells you how to fix it:
In the future, we will add other handling objects to achieve efficiency.