DEV Community

Discussion on: Comparing error handling in Java, Go and Rust.

Collapse
 
roddi profile image
Ruotger Deecke

If you look at Swift you will see, that it has all all the mechanisms above. defer {} for the cases where RAII is just to much boiler plate code. Enums with associated types for wrapping results together with errors (unfortunately the standard library is not there yet) and a try-catch mechanism that has the added bonus that it uses error objects instead of exceptions and the compiler enforces catching in the current context so you don't have exceptions flying all over the place.

Actually I don't think you can generally say that one concept is better than the others for all cases. As always: trade-offs