|
|
|
|
|
by chlorion
1503 days ago
|
|
>Panic is idiomatic error handling. Take something as basic as indexing into a list. Get it wrong and Rust will panic. This is not really true. If you are indexing into something that may fail you use the `get` method which returns an `Option` if the index is out of bounds. The index operator is just a shorthand for `v.get(i).unwrap()` pretty much. https://doc.rust-lang.org/std/primitive.slice.html#method.ge... |
|
The panic mentality comes from people who have spent most of their life writing C++, in which if anything goes wrong like an out of bounds index, memory might be corrupted in arbitrary ways, and in which you don't have a GC to clean up after you. Writing exception safe code is much easier in type safe GCd languages, and many programming errors end up being recoverable.