Skip to content

Commit a95c62d

Browse files
committed
Move explanation up as per @aturon
1 parent c7ae434 commit a95c62d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/ch07-02-unrecoverable-errors-with-panic.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ fn main() {
3939
```
4040
4141
We attempt to access the hundredth element of our vector, but it only has three
42-
elements. In this situation, Rust will panic. Let's try it:
42+
elements. In this situation, Rust will panic. Using `[]` is supposed to return
43+
a number. But if you pass it an invalid index, there's no number Rust could
44+
return here, it would be wrong. So the only thing that we can do is terminate
45+
the program.
46+
47+
Let's try to run it:
4348
4449
```bash
4550
$ cargo run
@@ -97,8 +102,3 @@ error: Process didn't exit successfully: `target/debug/panic` (exit code: 101)
97102
98103
That's a lot of output! Line `11` there has the line in our project:
99104
`src/main.rs` line four.
100-
101-
So why does Rust panic here? In this case, using `[]` is supposed to return
102-
a number. But if you pass it an invalid index, there's no number Rust could
103-
return here, it would be wrong. So the only thing that we can do is terminate
104-
the program.

0 commit comments

Comments
 (0)