There is no try, expect in roc and I like this decision.
In most cases, this is not needed, since "unsafe" functions return a Result that can be checked in a safe way. For example to get the first element of a list is unsafe in a lot of langues. To write list[1] in go could panic. In roc, List.get list 1 can not.
But its different with numbers and overflow. I understand, that it would be very annoying, if 255 + 1 would return a Result. But on the other hand, it is annoying, to check values, before doing the calculation.
if x == 0 then
Err ToSmall
else
Ok (x - 1)
Would it be possible to add a Num.catch function, just to catch the panics, that come from calculations?
when Num.catch (x-1) is
Ok n -> ...
Err AdditionOverflow -> ...
Or is there another way how to handle the overflow errors without checking each value first?
There’s a class of checked functions: https://www.roc-lang.org/builtins/Num#addChecked
I assume the hope here is to group many ops and then check the result all at once? Wouldn't be super convenient, but the best way to do it would probably be backpassing with Result.try and the checked functions. Then just check the final result.
Definitely a lot more verbose to get checking here
I did know about these checked functions. Not so convenient, but I will give them a try
7 messages were moved from this topic to #ideas > Better Backtraces by Brendan Hansknecht.
Oskar, let us know how this goes, would love to see how the code works out. Maybe it will be really bad in terms of ergonomics and we should look at a way to making it automatic for number types. Would be nice to just brainstorm depending on ergonomics.
Last updated: Jun 16 2026 at 16:19 UTC