docs: give a concrete example of bounds access check, and error propagation with `x := arr[idx] ?`

pull/12299/head
Delyan Angelov 2021-10-25 17:19:24 +03:00
parent ac99007cab
commit 5b325b99e8
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 4 additions and 0 deletions

View File

@ -1102,6 +1102,10 @@ The same optional check applies to arrays:
arr := [1, 2, 3] arr := [1, 2, 3]
large_index := 999 large_index := 999
val := arr[large_index] or { panic('out of bounds') } val := arr[large_index] or { panic('out of bounds') }
println(val)
// you can also do this, if you want to *propagate* the access error:
val2 := arr[333] ?
println(val2)
``` ```
## Module imports ## Module imports