Skip to content

Commit 96ce6a4

Browse files
dgarlittJosé Valim
authored and
José Valim
committed
Fix example exceptions for structs
Updated the following example exceptions for structs in the getting-started guide: - when using pattern matching to update a field that doesn't exist in a struct - when trying to directly access a field in a struct - when trying to use the Dict.get method to access a field in a struct Signed-off-by: José Valim <[email protected]>
1 parent 0808567 commit 96ce6a4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

getting-started/structs.markdown

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ iex> john.name
6464
iex> meg = %{john | name: "Meg"}
6565
%User{age: 27, name: "Meg"}
6666
iex> %{meg | oops: :field}
67-
** (ArgumentError) argument error
67+
** (KeyError) key :oops not found in: %User{age: 27, name: "Meg"}
6868
```
6969

7070
When using the update syntax (`|`), the <abbr title="Virtual Machine">VM</abbr> is aware that no new keys will be added to the struct, allowing the maps underneath to share their structure in memory. In the example above, both `john` and `meg` share the same key structure in memory.
@@ -97,7 +97,7 @@ Notice that we referred to structs as **bare** maps because none of the protocol
9797
iex> john = %User{}
9898
%User{age: 27, name: "John"}
9999
iex> john[:name]
100-
** (Protocol.UndefinedError) protocol Access not implemented for %User{age: 27, name: "John"}
100+
** (UndefinedFunctionError) undefined function: User.fetch/2
101101
iex> Enum.each john, fn({field, value}) -> IO.puts(value) end
102102
** (Protocol.UndefinedError) protocol Enumerable not implemented for %User{age: 27, name: "John"}
103103
```

0 commit comments

Comments
 (0)