Panics
๋ฌ์คํธ๋ ๋ฐํ์์์ ์น๋ช ์ ์ธ ์ค๋ฅ๋ฅผ ๋ง๋๋ฉด ํจ๋์ ๋ฐ์ํ ๊ฒ์ ๋๋ค:
Rust will trigger a panic if a fatal error happens at runtime:
fn main() { let v = vec![10, 20, 30]; println!("v[100]: {}", v[100]); }
- ํจ๋์ ๋ณต๊ตฌํ ์ ์๊ณ ์์์น ๋ชปํ ์ค๋ฅ์
๋๋ค.
- ํจ๋์ ํ๋ก๊ทธ๋จ ๋ฒ๊ทธ์ ์ฆ์์ ๋๋ค.
- ์ถฉ๋(ํฌ๋์)๋ฅผ ํ์ฉํ์ง ์์์ผ ํ๋ ๊ฒฝ์ฐ ํจ๋์ ์ ๋ฐํ์ง ์๋(non-panicking) API๋ฅผ ์ฌ์ฉํฉ๋๋ค.(
Vec::get
๋ฑ)
- Panics are for unrecoverable and unexpected errors.
- Panics are symptoms of bugs in the program.
- Use non-panicking APIs (such as
Vec::get
) if crashing is not acceptable.
์ญ์ฃผ
- ์ ์์ ์์ v[100]์ v.get(100) ์ผ๋ก ๋์ฒดํด๋ณด์ธ์